-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogger.go
45 lines (36 loc) · 1.1 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
package main
import (
"os"
"time"
"github.com/rs/zerolog"
"gopkg.in/natefinch/lumberjack.v2"
)
/*
* Setup logger to the file and stdout.
*
* In a production environment log events to the file only,
* in a development environment log to the stdout only
*/
func setupLogger() error {
// For the production server
if config.Environment == "prod" {
// Lumberjack provides log files rotation
log = zerolog.New(&lumberjack.Logger{
Filename: config.Log.File,
MaxSize: config.Log.MaxSize, // Size in MB before file gets rotated
MaxBackups: config.Log.MaxBackups, // Max number of files kept before being overwritten
MaxAge: config.Log.MaxAge, // Max number of days to keep the files
Compress: true, // Whether to compress log files using gzip
}).With().Timestamp().Logger()
zerolog.SetGlobalLevel(config.Log.Level)
return nil
}
// For the development
stdout := zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
}
log = zerolog.New(stdout).With().Timestamp().Logger()
zerolog.SetGlobalLevel(config.Log.Level)
return nil
}