forked from limetext/lime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
113 lines (97 loc) · 2.17 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
105
106
107
108
109
110
111
112
113
// Copyright 2014 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package log
import (
"github.com/limetext/log4go"
)
type (
Logger struct {
logger log4go.Logger
}
)
func NewLogger() *Logger {
l := &Logger{
logger: make(log4go.Logger),
}
return l
}
func (l *Logger) AddFilter(name string, level Level, writer LogWriter) {
lvl := log4go.INFO
switch level {
case FINEST:
lvl = log4go.FINEST
case FINE:
lvl = log4go.FINE
case DEBUG:
lvl = log4go.DEBUG
case TRACE:
lvl = log4go.TRACE
case INFO:
lvl = log4go.INFO
case WARNING:
lvl = log4go.WARNING
case ERROR:
lvl = log4go.ERROR
case CRITICAL:
lvl = log4go.CRITICAL
default:
}
l.logger.AddFilter(name, lvl, writer)
}
func (l *Logger) Finest(arg0 interface{}, args ...interface{}) {
l.logger.Finest(arg0, args...)
}
func (l *Logger) Fine(arg0 interface{}, args ...interface{}) {
l.logger.Fine(arg0, args...)
}
func (l *Logger) Debug(arg0 interface{}, args ...interface{}) {
l.logger.Debug(arg0, args...)
}
func (l *Logger) Trace(arg0 interface{}, args ...interface{}) {
l.logger.Trace(arg0, args...)
}
func (l *Logger) Info(arg0 interface{}, args ...interface{}) {
l.logger.Info(arg0, args...)
}
func (l *Logger) Warn(arg0 interface{}, args ...interface{}) {
l.logger.Warn(arg0, args...)
}
func (l *Logger) Error(arg0 interface{}, args ...interface{}) {
l.logger.Error(arg0, args...)
}
func (l *Logger) Errorf(format string, args ...interface{}) {
l.Logf(ERROR, format, args...)
}
func (l *Logger) Critical(arg0 interface{}, args ...interface{}) {
l.logger.Critical(arg0, args...)
}
func (l *Logger) Logf(level Level, format string, args ...interface{}) {
lvl := log4go.INFO
switch level {
case FINEST:
lvl = log4go.FINEST
case FINE:
lvl = log4go.FINE
case DEBUG:
lvl = log4go.DEBUG
case TRACE:
lvl = log4go.TRACE
case INFO:
lvl = log4go.INFO
case WARNING:
lvl = log4go.WARNING
case ERROR:
lvl = log4go.ERROR
case CRITICAL:
lvl = log4go.CRITICAL
default:
}
l.logger.Logf(lvl, format, args...)
}
func (l *Logger) Close(args ...interface{}) {
if len(args) > 0 {
l.Error(args)
}
l.logger.Close()
}