42 lines
851 B
Go
42 lines
851 B
Go
|
package logger
|
||
|
|
||
|
import (
|
||
|
c "live-streamer/config"
|
||
|
"os"
|
||
|
"strings"
|
||
|
|
||
|
"go.uber.org/zap"
|
||
|
"go.uber.org/zap/zapcore"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
GlobalLogger *zap.Logger
|
||
|
config *c.Config
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
config = c.GlobalConfig
|
||
|
|
||
|
var logLevel zapcore.Level
|
||
|
switch strings.ToLower(config.Log.Level) {
|
||
|
case "info":
|
||
|
logLevel = zap.InfoLevel
|
||
|
case "error":
|
||
|
logLevel = zap.ErrorLevel
|
||
|
case "warn":
|
||
|
logLevel = zap.WarnLevel
|
||
|
case "debug":
|
||
|
logLevel = zap.DebugLevel
|
||
|
case "panic":
|
||
|
logLevel = zap.PanicLevel
|
||
|
}
|
||
|
|
||
|
encoderConfig := zap.NewProductionEncoderConfig()
|
||
|
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
|
||
|
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||
|
|
||
|
consoleWriter := zapcore.AddSync(os.Stdout)
|
||
|
consoleCore := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderConfig), consoleWriter, logLevel)
|
||
|
GlobalLogger = zap.New(consoleCore)
|
||
|
}
|