-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiLoggerExternals.go
70 lines (62 loc) · 1.87 KB
/
MultiLoggerExternals.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
package goweb
import (
"fmt"
"os"
"time"
)
func (l *LogHandler) Debug(m string) {
l.dispatch(LEVEL_DEBUG, m)
}
func (l *LogHandler) Info(m string) {
l.dispatch(LEVEL_INFO, m)
}
func (l *LogHandler) Warn(m string) {
l.dispatch(LEVEL_WARN, m)
}
func (l *LogHandler) Error(m string) {
l.dispatch(LEVEL_ERROR, m)
}
func (l *LogHandler) Critical(m string) {
l.dispatch(LEVEL_CRITICAL, m)
}
func (l *LogHandler) Fatal(m string) {
l.dispatch(LEVEL_CRITICAL, m)
os.Exit(1)
}
func (l *LogHandler) dispatch(logLevel int, m string) {
var mm string
if logLevel == LEVEL_DEBUG {
mm = fmt.Sprintf("DEBUG %s %s", l.Header, m)
} else if logLevel == LEVEL_INFO {
mm = fmt.Sprintf("INFO %s %s", l.Header, m)
} else if logLevel == LEVEL_WARN {
mm = fmt.Sprintf("WARN %s %s", l.Header, m)
} else if logLevel == LEVEL_ERROR {
mm = fmt.Sprintf("ERROR %s %s", l.Header, m)
} else if logLevel == LEVEL_CRITICAL {
mm = fmt.Sprintf("CRITICAL %s %s", l.Header, m)
}
mm = fmt.Sprintf("%s %s[%d]: %s", time.Now().UTC().Format("Jan 02 15:04:05-0700"), l.ServiceName, l.pid, mm)
for i := 0; i < len(l.Dispatchers); i++ {
if (l.Dispatchers[i].LogLevel >= logLevel && l.Header != LOGHEADER_RPCWEB) ||
(l.Dispatchers[i].RpcLogLevel >= logLevel && l.Header == LOGHEADER_RPCWEB) {
if l.Dispatchers[i].SysLog != nil {
if logLevel == LEVEL_DEBUG {
l.Dispatchers[i].SysLog.Debug(mm)
} else if logLevel == LEVEL_INFO {
l.Dispatchers[i].SysLog.Info(mm)
} else if logLevel == LEVEL_WARN {
l.Dispatchers[i].SysLog.Warning(mm)
} else if logLevel == LEVEL_ERROR {
l.Dispatchers[i].SysLog.Err(mm)
} else if logLevel == LEVEL_CRITICAL {
l.Dispatchers[i].SysLog.Crit(mm)
}
} else if l.Dispatchers[i].Stdout != nil {
l.Dispatchers[i].Stdout.Println(mm)
} else if l.Dispatchers[i].Stderr != nil {
l.Dispatchers[i].Stderr.Println(mm)
}
}
}
}