forked from dedis/ci_setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.go
57 lines (47 loc) · 1.19 KB
/
mod.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
// Package ci_example defines the logger.
//
// package is using a global logger with some default parameters.
// It is disabled by default and the level can be increased using
// an environment variable:
//
// MY_LOG=trace
// MY_LOG=info
package ci_example
import (
"os"
"time"
"github.com/rs/zerolog"
)
// EnvLogLevel is the name of the environment variable to change the logging
// level.
const EnvLogLevel = "MY_LOG"
const defaultLogLevel = zerolog.WarnLevel
func init() {
lvl := os.Getenv(EnvLogLevel)
var level zerolog.Level
switch lvl {
case "error":
level = zerolog.ErrorLevel
case "warn":
level = zerolog.WarnLevel
case "info":
level = zerolog.InfoLevel
case "debug":
level = zerolog.DebugLevel
case "trace":
level = zerolog.TraceLevel
case "disabled":
level = zerolog.Disabled
default:
level = defaultLogLevel
}
Logger = Logger.Level(level)
}
var logout = zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
}
// Logger is a globally available logger instance. By default, it only prints
// error level messages but it can be changed through a environment variable.
var Logger = zerolog.New(logout).Level(defaultLogLevel).
With().Timestamp().Logger()