36 lines
699 B
Go
36 lines
699 B
Go
|
package common
|
||
|
|
||
|
import (
|
||
|
scn "blackforestbytes.com/simplecloudnotifier"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/rs/zerolog"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func Init(cfg scn.Config) {
|
||
|
cw := zerolog.ConsoleWriter{
|
||
|
Out: os.Stdout,
|
||
|
TimeFormat: "2006-01-02 15:04:05 Z07:00",
|
||
|
}
|
||
|
|
||
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||
|
multi := zerolog.MultiLevelWriter(cw)
|
||
|
logger := zerolog.New(multi).With().
|
||
|
Timestamp().
|
||
|
Caller().
|
||
|
Logger()
|
||
|
|
||
|
log.Logger = logger
|
||
|
|
||
|
if cfg.GinDebug {
|
||
|
gin.SetMode(gin.DebugMode)
|
||
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||
|
} else {
|
||
|
gin.SetMode(gin.ReleaseMode)
|
||
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||
|
}
|
||
|
|
||
|
log.Debug().Msg("Initialized")
|
||
|
}
|