forked from cert-lv/graphoscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
41 lines (32 loc) · 818 Bytes
/
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
package main
import (
"os"
"time"
"github.com/rs/zerolog"
)
/*
* 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() (*os.File, error) {
// For the production server
if config.Environment == "prod" {
file, err := os.OpenFile(config.Log.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
return nil, err
}
log = zerolog.New(file).With().Timestamp().Logger()
zerolog.SetGlobalLevel(config.Log.Level)
return file, 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, nil
}