-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
43 lines (34 loc) · 896 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
42
43
package tools
import (
"os"
"github.com/sirupsen/logrus"
)
// For more information: https://github.com/sirupsen/logrus/blob/master/example_basic_test.go
// If we want to use a specific logging service there
// are multiple formatters implementations here: https://github.com/sirupsen/logrus#formatters
var log *logrus.Logger //nolint
func InitializeLogger() {
if isProduction() {
initializeLoggerForProduction()
} else {
initializeLogger()
}
}
func isProduction() bool {
return os.Getenv("AUTH_SERVER_APP_ENV") == "production"
}
func initializeLoggerForProduction() {
initializeLogger()
log.Level = logrus.InfoLevel
log.SetReportCaller(false)
}
func initializeLogger() {
log = logrus.New()
log.Formatter = &logrus.TextFormatter{FullTimestamp: true}
log.SetReportCaller(true)
log.Level = logrus.TraceLevel
log.Out = os.Stdout
}
func Log() *logrus.Logger {
return log
}