mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 20:05:17 +03:00
feat: create init log system
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -40,3 +41,15 @@ func (c *Config) GetURLPostgres() string {
|
||||
c.DBPort,
|
||||
c.DBName)
|
||||
}
|
||||
|
||||
func (c *Config) GetLogLevel() zerolog.Level {
|
||||
level, err := zerolog.ParseLevel(c.LogLevel)
|
||||
if err != nil {
|
||||
return zerolog.InfoLevel
|
||||
}
|
||||
return level
|
||||
}
|
||||
|
||||
func (c *Config) GetMode() string {
|
||||
return c.Mode
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type cfgLogStore interface {
|
||||
GetLogLevel() zerolog.Level
|
||||
GetMode() string
|
||||
}
|
||||
|
||||
func Init(cfg cfgLogStore) {
|
||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
|
||||
if cfg.GetMode() != "PROD" {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{
|
||||
Out: os.Stdout,
|
||||
TimeFormat: time.Kitchen,
|
||||
})
|
||||
} else {
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user