add logging
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
5089535fce
commit
e1aff8d16b
7 changed files with 73 additions and 33 deletions
|
|
@ -1,12 +1,16 @@
|
|||
package config
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
DB DBConfig `mapstructure:"db"`
|
||||
DataDir string `mapstructure:"data_dir"`
|
||||
Sync SyncConfig `mapstructure:"sync"`
|
||||
Log LogConfig `mapstructure:"log"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
|
|
@ -22,6 +26,24 @@ type SyncConfig struct {
|
|||
Interval string `mapstructure:"interval"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Level string `mapstructure:"level"`
|
||||
Format string `mapstructure:"format"`
|
||||
}
|
||||
|
||||
func (l LogConfig) SlogLevel() slog.Level {
|
||||
switch l.Level {
|
||||
case "debug":
|
||||
return slog.LevelDebug
|
||||
case "warn", "warning":
|
||||
return slog.LevelWarn
|
||||
case "error":
|
||||
return slog.LevelError
|
||||
default:
|
||||
return slog.LevelInfo
|
||||
}
|
||||
}
|
||||
|
||||
func (s SyncConfig) IntervalDuration() time.Duration {
|
||||
d, err := time.ParseDuration(s.Interval)
|
||||
if err != nil || d <= 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue