-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlogger.go
51 lines (43 loc) · 1.32 KB
/
logger.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
package libschema
import (
"github.com/muir/libschema/internal"
"github.com/muir/testinglogur"
)
type Logur interface {
Trace(msg string, fields ...map[string]interface{})
Debug(msg string, fields ...map[string]interface{})
Info(msg string, fields ...map[string]interface{})
Warn(msg string, fields ...map[string]interface{})
Error(msg string, fields ...map[string]interface{})
}
// LogFromLogur creates a logger for libschema from a logger that
// implments the recommended interface in Logur.
// See https://github.com/logur/logur#readme
func LogFromLogur(logur Logur) *internal.Log {
return &internal.Log{
Logur: logur,
}
}
// LogFromPrintln creates a logger for libchema from a logger that implements
// Println() like the standard "log" pacakge.
//
// import "log"
//
// LogFromPrintln(log.Default())
//
func LogFromPrintln(printer interface{ Println(...interface{}) }) *internal.Log {
return LogFromLog(printlnToLog{printer})
}
type printlnToLog struct {
println interface{ Println(...interface{}) }
}
func (p printlnToLog) Log(v ...interface{}) {
p.println.Println(v...)
}
// LogFromPrintln creates a logger for libschema from a logger that implements
// Log() like testing.T does.
func LogFromLog(logger interface{ Log(...interface{}) }) *internal.Log {
return &internal.Log{
Logur: testinglogur.Get(logger),
}
}