This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.go
104 lines (87 loc) · 2.24 KB
/
log.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package log
import (
"github.com/ronaksoft/rony/di"
"go.uber.org/zap/zapcore"
)
/*
Creation Time: 2021 - Sep - 01
Created by: (ehsan)
Maintainers:
1. Ehsan N. Moosa (E2)
Auditor: Ehsan N. Moosa (E2)
Copyright Ronak Software Group 2020
*/
var (
DefaultLogger *ronyLogger
)
type (
Level = zapcore.Level
Field = zapcore.Field
FieldType = zapcore.FieldType
CheckedEntry = zapcore.CheckedEntry
DurationEncoder = zapcore.DurationEncoder
CallerEncode = zapcore.CallerEncoder
LevelEncoder = zapcore.LevelEncoder
TimeEncoder = zapcore.TimeEncoder
)
type Logger interface {
Debug(msg string, fields ...Field)
Info(msg string, fields ...Field)
Warn(msg string, fields ...Field)
Error(msg string, fields ...Field)
Fatal(msg string, fields ...Field)
Check(Level, string) *CheckedEntry
Sugared() *sugaredRonyLogger
SetLevel(level Level)
With(name string) Logger
}
type SugaredLogger interface {
Debugf(template string, args ...interface{})
Infof(template string, args ...interface{})
Printf(template string, args ...interface{})
Warnf(template string, args ...interface{})
Errorf(template string, args ...interface{})
Fatalf(template string, args ...interface{})
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Panic(args ...interface{})
}
func init() {
cfg := DefaultConfig
cfg.SkipCaller = 3
DefaultLogger = New(cfg)
// bind *ronyLogger for dependency injection
di.MustProvide(func(l *ronyLogger) Logger {
return l
})
}
func Init(config Config) {
DefaultLogger = New(config)
}
func Debug(msg string, fields ...Field) {
DefaultLogger.Debug(msg, fields...)
}
func Info(msg string, fields ...Field) {
DefaultLogger.Info(msg, fields...)
}
func Warn(msg string, fields ...Field) {
DefaultLogger.Warn(msg, fields...)
}
func Error(msg string, fields ...Field) {
DefaultLogger.Error(msg, fields...)
}
func Fatal(msg string, fields ...Field) {
DefaultLogger.Fatal(msg, fields...)
}
func Check(level Level, msg string) *CheckedEntry {
return DefaultLogger.Check(level, msg)
}
func SetLevel(level Level) {
DefaultLogger.SetLevel(level)
}
func With(name string) Logger {
return DefaultLogger.With(name)
}