-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompatibility.go
More file actions
72 lines (56 loc) · 1.97 KB
/
compatibility.go
File metadata and controls
72 lines (56 loc) · 1.97 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package logger
import (
"context"
"fmt"
)
// Logger defines an interface that is compatible with golang's standard log system. To use it
// configure a context using this packages setup functions, then create a LoggerObject with
// NewLoggerObject and that context. It is then mostly interchangeable with a golang log object
// though you still need to use this interface as the type in function parameters.
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Fatalln(v ...interface{})
Panic(v ...interface{})
Panicf(format string, v ...interface{})
Panicln(v ...interface{})
}
type LoggerObject struct {
ctx context.Context
}
func NewLoggerObject(ctx context.Context) *LoggerObject {
return &LoggerObject{ctx}
}
func (l *LoggerObject) Print(v ...interface{}) {
LogDepth(l.ctx, LevelInfo, GetCaller(1), fmt.Sprint(v...))
}
func (l *LoggerObject) Printf(format string, v ...interface{}) {
LogDepth(l.ctx, LevelInfo, GetCaller(1), format, v...)
}
func (l *LoggerObject) Println(v ...interface{}) {
LogDepth(l.ctx, LevelInfo, GetCaller(1), fmt.Sprint(v...))
}
func (l *LoggerObject) Fatal(v ...interface{}) {
LogDepth(l.ctx, LevelFatal, GetCaller(1), fmt.Sprint(v...))
}
func (l *LoggerObject) Fatalf(format string, v ...interface{}) {
LogDepth(l.ctx, LevelFatal, GetCaller(1), format, v...)
}
func (l *LoggerObject) Fatalln(v ...interface{}) {
LogDepth(l.ctx, LevelFatal, GetCaller(1), fmt.Sprint(v...))
}
func (l *LoggerObject) Panic(v ...interface{}) {
LogDepth(l.ctx, LevelPanic, GetCaller(1), fmt.Sprint(v...))
}
func (l *LoggerObject) Panicf(format string, v ...interface{}) {
LogDepth(l.ctx, LevelPanic, GetCaller(1), format, v...)
}
func (l *LoggerObject) Panicln(v ...interface{}) {
LogDepth(l.ctx, LevelPanic, GetCaller(1), fmt.Sprint(v...))
}
func (l *LoggerObject) AddFields(fields []Field) {
l.ctx = ContextWithLogFields(l.ctx, fields...)
}