-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.go
143 lines (112 loc) · 2.6 KB
/
default.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package log
import (
"log"
"os"
"github.com/go-baa/setting"
)
// _defaultLogger 日志接口
var _defaultLogger Logger
// Default 返回默认日志器
func Default() Logger {
return _defaultLogger
}
func Level() LogLevel {
return _defaultLogger.Level()
}
func SetLevel(l LogLevel) {
_defaultLogger.SetLevel(l)
}
func SetCopy(ch chan string) {
_defaultLogger.SetCopy(ch)
}
func Flush() {
_defaultLogger.Flush()
}
func Print(v ...interface{}) {
_defaultLogger.Print(v...)
}
func Printf(format string, v ...interface{}) {
_defaultLogger.Printf(format, v...)
}
func Println(v ...interface{}) {
_defaultLogger.Println(v...)
}
func Fatal(v ...interface{}) {
_defaultLogger.Fatal(v...)
}
func Fatalf(format string, v ...interface{}) {
_defaultLogger.Fatalf(format, v...)
}
func Fatalln(v ...interface{}) {
_defaultLogger.Fatalln(v...)
}
func Panic(v ...interface{}) {
_defaultLogger.Panic(v...)
}
func Panicf(format string, v ...interface{}) {
_defaultLogger.Panicf(format, v...)
}
func Panicln(v ...interface{}) {
_defaultLogger.Panicln(v...)
}
func Error(v ...interface{}) {
_defaultLogger.Error(v...)
}
func Errorf(format string, v ...interface{}) {
_defaultLogger.Errorf(format, v...)
}
func Errorln(v ...interface{}) {
_defaultLogger.Errorln(v...)
}
func Warn(v ...interface{}) {
_defaultLogger.Warn(v...)
}
func Warnf(format string, v ...interface{}) {
_defaultLogger.Warnf(format, v...)
}
func Warnln(v ...interface{}) {
_defaultLogger.Warnln(v...)
}
func Info(v ...interface{}) {
_defaultLogger.Info(v...)
}
func Infof(format string, v ...interface{}) {
_defaultLogger.Infof(format, v...)
}
func Infoln(v ...interface{}) {
_defaultLogger.Infoln(v...)
}
func Debug(v ...interface{}) {
_defaultLogger.Debug(v...)
}
func Debugf(format string, v ...interface{}) {
_defaultLogger.Debugf(format, v...)
}
func Debugln(v ...interface{}) {
_defaultLogger.Debugln(v...)
}
func Output(calldepth int, s string) error {
_defaultLogger.(*tLogger).SetCallerLevel(calldepth)
_defaultLogger.Println(s)
return nil
}
func init() {
var f *os.File
file := setting.Config.MustString("log.file", "")
if file == "" || file == "os.Stderr" {
f = os.Stderr
} else if file == "os.Stdout" {
f = os.Stdout
} else {
var err error
f, err = os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening logfile: %v\n", err)
}
// 不能关闭文件
//defer f.Close()
}
_defaultLogger = New(f, "["+setting.AppName+"] ", log.LstdFlags)
_defaultLogger.SetLevel(LogLevel(setting.Config.MustInt("log.level", int(LOG_WARN))))
_defaultLogger.(*tLogger).SetCallerLevel(3)
}