forked from coaidev/coai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
69 lines (54 loc) · 1.09 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package globals
import (
"fmt"
"github.com/natefinch/lumberjack"
"github.com/sirupsen/logrus"
"strings"
)
var Logger *logrus.Logger
type AppLogger struct {
*logrus.Logger
}
func (l *AppLogger) Format(entry *logrus.Entry) ([]byte, error) {
data := fmt.Sprintf(
"[%s] - [%s] - %s\n",
strings.ToUpper(entry.Level.String()),
entry.Time.Format("2006-01-02 15:04:05"),
entry.Message,
)
return []byte(data), nil
}
func init() {
Logger = logrus.New()
Logger.SetFormatter(&AppLogger{
Logger: Logger,
})
Logger.SetOutput(&lumberjack.Logger{
Filename: "logs/chat.log",
MaxSize: 1,
MaxBackups: 500,
MaxAge: 1,
})
Logger.SetLevel(logrus.DebugLevel)
}
func Output(args ...interface{}) {
Logger.Println(args...)
}
func Debug(args ...interface{}) {
Logger.Debugln(args...)
}
func Info(args ...interface{}) {
Logger.Infoln(args...)
}
func Warn(args ...interface{}) {
Logger.Warnln(args...)
}
func Error(args ...interface{}) {
Logger.Errorln(args...)
}
func Fatal(args ...interface{}) {
Logger.Fatalln(args...)
}
func Panic(args ...interface{}) {
Logger.Panicln(args...)
}