-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
54 lines (40 loc) · 1.16 KB
/
main.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
package main
import "github.com/kataras/golog"
func main() {
golog.Child("Router").Infof("Route %s regirested", "/mypath")
// registerRoute("/mypath")
golog.Child("Router").Warnf("Route %s already exists, skipping second registration", "/mypath")
golog.Error("Something went wrong!")
var (
srvLogger = golog.Child("Server")
app1Logger = srvLogger.Child("App1")
// Or use a pointer as child's key and append the prefix manually:
app2 = newApp("App2")
app2Logger = srvLogger.Child(app2).
SetChildPrefix(app2.Name).
SetLevel("debug")
// Or use a pointer to a value which implements the fmt.Stringer:
app3 = newAppWithString("App3")
app3Logger = srvLogger.Child(app3)
)
srvLogger.Infof("Hello Server")
app1Logger.Infof("Hello App1")
app2Logger.Debugf("Hello App2")
app3Logger.Warnf("Hello App3")
srvLogger.LastChild().Infof("Hello App3 again")
}
type app struct {
Name string
}
func newApp(name string) *app {
return &app{Name: name}
}
type appWithString struct {
name string
}
func newAppWithString(name string) *appWithString {
return &appWithString{name: name}
}
func (app *appWithString) String() string {
return app.name
}