-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
57 lines (45 loc) · 1.3 KB
/
logging.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package sup
import (
"fmt"
"os"
"strings"
)
type WritName []string
func (wn WritName) String() string {
if len(wn) == 0 {
return "[root]"
}
return strings.Join(wn, ".")
}
func (wn WritName) Coda() string {
if len(wn) == 0 {
return "[root]"
}
return wn[len(wn)-1]
}
func (wn WritName) New(segment string) WritName {
result := make([]string, len(wn)+1)
copy(result, wn)
result[len(wn)] = segment
return result
}
/*
Called to log lifecycle events inside the supervision system.
An example event might be
log(mgr.FullName, "child reaped", writ.Name)
which one might log as, for example:
log.debug(evt, {"mgr":name, "regarding":re.Coda()})
//debug: child reaped -- mgr=root.system.subsys regarding=subproc14
The `name` and `evt` parameters will always be nonzero; `re` is optional.
The `important` parameter will be true if this should *really* be printed;
"important" events are low-volume things and generally warnings, like
the warnings printed for agents that are not responding to quit signals.
*/
type LogFn func(name WritName, evt string, re WritName, important bool)
var log LogFn = func(name WritName, evt string, re WritName, _ bool) {
if re == nil {
fmt.Fprintf(os.Stderr, "mgr=%s: %q\n", name, evt)
} else {
fmt.Fprintf(os.Stderr, "mgr=%s: %q re=%s\n", name, evt, re.Coda())
}
}