forked from limetext/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
83 lines (75 loc) · 1.78 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
// 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 interface {
AddFilter(name string, level Level, writer LogWriter)
Finest(arg0 interface{}, args ...interface{})
Fine(arg0 interface{}, args ...interface{})
Debug(arg0 interface{}, args ...interface{})
Trace(arg0 interface{}, args ...interface{})
Info(arg0 interface{}, args ...interface{})
Warn(arg0 interface{}, args ...interface{}) error
Error(arg0 interface{}, args ...interface{}) error
Critical(arg0 interface{}, args ...interface{}) error
Logf(level Level, format string, args ...interface{})
Close()
}
type logger struct {
log4go.Logger
}
func NewLogger() Logger {
return &logger{make(log4go.Logger)}
}
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) 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) Errorf(format string, args ...interface{}) {
l.Logf(ERROR, format, args...)
}