-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
67 lines (57 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
67 lines (57 loc) · 1.29 KB
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
package main
import (
"github.com/go-yaml/yaml"
"github.com/timoguin/goldap/cmd"
"go.uber.org/zap"
)
var (
Version string
GitCommit string
GoVersion string
PlainLogger *zap.Logger
Logger *zap.SugaredLogger
LoggerConfig *zap.Config
)
func main() {
// Set built-time vars in the cmd package so we can access them in commands
cmd.Version = Version
cmd.GitCommit = GitCommit
cmd.GoVersion = GoVersion
// Configure logging
if err := yaml.Unmarshal([]byte(DefaultLoggerConfig), &LoggerConfig); err != nil {
panic(err)
}
PlainLogger, err := LoggerConfig.Build()
if err != nil {
panic(err)
}
defer PlainLogger.Sync()
// Redirect the standard library's global logger
zap.RedirectStdLogAt(PlainLogger, zap.DebugLevel)
// Create SugaredLogger
Logger = PlainLogger.Sugar()
// Pass loggers to the cmd package
cmd.PlainLogger = PlainLogger
cmd.Logger = Logger
cmd.LoggerConfig = LoggerConfig
cmd.Execute()
}
const DefaultLoggerConfig = `---
level: debug
development: true
disableCaller: false
disableStacktrace: false
sampling: null
encoderConfig:
levelKey: level
messageKey: msg
levelEncoder: lowercase
encoding: json
outputPaths:
- stdout
- /tmp/goldap.log
errorOutputPaths:
- stderr
- /tmp/goldap.error.log
initialFields: {}
}`