-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
39 lines (34 loc) · 882 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
package logger
import (
"os"
"github.com/drj-sharma/glogger/lib"
log "github.com/sirupsen/logrus"
)
type Logger struct {
Level log.Level
}
// Parsing the log level from the passing argument.
func (l *Logger) parseLoggerLevel(lvl string) (log.Level, error) {
level, err := log.ParseLevel(lvl)
if err != nil {
return log.DebugLevel, err
}
return level, nil
}
// Creating a new logger and setting the log level and formatter.
func (l *Logger) GetLogger() *log.Logger {
logger := log.New()
level := os.Getenv("LOG_LEVEL")
logLevel, _ := l.parseLoggerLevel(level)
logger.Level = logLevel
logger.SetOutput(&lib.LogWriter{})
logger.Formatter = &lib.Formatter{
LogFormatter: log.TextFormatter{
FullTimestamp: true,
TimestampFormat: lib.REFERENCE_TIME,
ForceColors: false,
DisableLevelTruncation: false,
},
}
return logger
}