forked from TarsCloud/TarsGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
65 lines (56 loc) · 1.43 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
package tars
import (
"path/filepath"
"github.com/TarsCloud/TarsGo/tars/util/rogger"
)
// GetLogger Get a logger
func GetLogger(name string) *rogger.Logger {
logPath, cfg, lg := getLogger(name)
if cfg == nil {
return lg
}
lg.SetFileRoller(logPath, int(cfg.LogNum), int(cfg.LogSize))
return lg
}
func getLogger(name string) (logPath string, cfg *serverConfig, lg *rogger.Logger) {
cfg = GetServerConfig()
if cfg == nil {
return "", nil, rogger.GetLogger(name)
}
if name == "" {
name = cfg.App + "." + cfg.Server
} else {
name = cfg.App + "." + cfg.Server + "_" + name
}
logPath = filepath.Join(cfg.LogPath, cfg.App, cfg.Server)
lg = rogger.GetLogger(name)
return
}
// GetDayLogger Get a logger roll by day
func GetDayLogger(name string, numDay int) *rogger.Logger {
logPath, _, lg := getLogger(name)
lg.SetDayRoller(logPath, numDay)
return lg
}
// GetHourLogger Get a logger roll by hour
func GetHourLogger(name string, numHour int) *rogger.Logger {
logPath, _, lg := getLogger(name)
lg.SetHourRoller(logPath, numHour)
return lg
}
// GetRemoteLogger returns a remote logger
func GetRemoteLogger(name string) *rogger.Logger {
cfg := GetServerConfig()
lg := rogger.GetLogger(name)
if !lg.IsConsoleWriter() {
return lg
}
remoteWriter := NewRemoteTimeWriter()
var set string
if cfg.Enableset {
set = cfg.Setdivision
}
remoteWriter.InitServerInfo(cfg.App, cfg.Server, name, set)
lg.SetWriter(remoteWriter)
return lg
}