-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocessor.go
37 lines (29 loc) · 918 Bytes
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2013 Marc Weistroff. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package log
import (
"runtime"
)
// RuntimeProcessor adds some information about the current go runtime to a log record
var RuntimeProcessor = NewProcessor(runtimeProcessor)
// A processor transforms a log records in whatever way it wants.
// It is usefull to add extra information to a log record
type Processor interface {
Process(*Record)
}
type processor struct {
process func(*Record)
}
// NewProcessor wraps a function to a Processor
func NewProcessor(f func(*Record)) Processor {
return &processor{process: f}
}
func (p *processor) Process(r *Record) {
p.process(r)
}
func runtimeProcessor(r *Record) {
r.Extra["go.num_cpu"] = runtime.NumCPU()
r.Extra["go.version"] = runtime.Version()
r.Extra["go.num_goroutines"] = runtime.NumGoroutine()
}