This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
104 lines (87 loc) · 2.47 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
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
// Copyright 2014 Daniel Qin. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package logger provide a general log interface
// Usage:
//
// import "github.com/nevernet/logger"
// logger.Trace("trace")
// logger.Info("info")
// logger.Warn("warning")
// logger.Debug("debug")
// logger.Critical("critical")
package logger
import (
"fmt"
"github.com/astaxie/beego/logs"
)
type logBridge struct {
}
var log *logs.BeeLogger
func init() {
log = logs.NewLogger(10000)
log.SetLogger("console", `{"level": 10}`)
log.SetLevel(logs.LevelDebug)
log.EnableFuncCallDepth(true)
log.SetLogFuncCallDepth(3)
log.Async()
}
// SetLogger reset the logger, default is console logger
func SetLogger(adapterName string, configs ...string) {
log.SetLogger(adapterName, configs...)
}
// GetLogger return the logger
func GetLogger() *logs.BeeLogger {
return log
}
// SetFileLogger is helper function for set file adapter
func SetFileLogger(filename string, maxlines int, maxsize int, daily bool, maxdays int, rotate bool, level string, separate string) {
configs := fmt.Sprintf(`{"filename":"%s", "maxlines":%d, "maxsize":%d, "daily":%t, "maxdays":%d, "rotate":%t, "level":"%s", "separate":"%s"}`,
filename, maxlines, maxsize, daily, maxdays, rotate, level, separate)
log.SetLogger(logs.AdapterFile, configs)
log.EnableFuncCallDepth(true)
log.SetLogFuncCallDepth(3)
log.Async()
}
// Trace log
func Trace(format string, v ...interface{}) {
log.Trace(format, v...)
}
// Debug log
func Debug(format string, v ...interface{}) {
log.Debug(format, v...)
}
// Info log
func Info(format string, v ...interface{}) {
log.Info(format, v...)
}
// Warn log
func Warn(format string, v ...interface{}) {
log.Warn(format, v...)
}
// Error log
func Error(format string, v ...interface{}) {
log.Error(format, v...)
}
// Critical log
func Critical(format string, v ...interface{}) {
log.Critical(format, v...)
}
// Flush log
func Flush() {
log.Flush()
}
// Close log
func Close() {
log.Close()
}