-
Notifications
You must be signed in to change notification settings - Fork 40
/
logger_config.go
60 lines (54 loc) · 1.31 KB
/
logger_config.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
package log
import (
"fmt"
"log"
lua "github.com/yuin/gopher-lua"
)
type luaLoggerOutputConfig struct {
date bool
time bool
microseconds bool
utc bool
longfile bool
}
func parseConfig(L *lua.LState, luaTable *lua.LTable) *luaLoggerOutputConfig {
config := &luaLoggerOutputConfig{}
parseBool := func(L *lua.LState, luaTable *lua.LTable, key string) bool {
if val1 := luaTable.RawGetString(key); val1.Type() != lua.LTNil {
if val2, ok := val1.(lua.LBool); ok {
return bool(val2)
} else {
L.ArgError(1, fmt.Sprintf("%s: must be bool", key))
}
}
return false
}
config.date = parseBool(L, luaTable, `date`)
config.time = parseBool(L, luaTable, `time`)
config.microseconds = parseBool(L, luaTable, `microseconds`)
config.utc = parseBool(L, luaTable, `utc`)
config.longfile = parseBool(L, luaTable, `longfile`)
return config
}
func setLogFlags(logger *luaLogger) {
goFlag := 0
if logger.config.date {
goFlag = log.Ldate
}
if logger.config.time {
goFlag = goFlag | log.Ltime
}
if logger.config.microseconds {
goFlag = goFlag | log.Lmicroseconds
}
if logger.config.utc {
goFlag = goFlag | log.LUTC
}
logger.Logger.SetFlags(goFlag)
}
func (c *luaLoggerOutputConfig) longfileValue(L *lua.LState) string {
if !c.longfile {
return ""
}
return L.Where(1)
}