add logging

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-25 20:00:00 +02:00
commit e1aff8d16b
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
7 changed files with 73 additions and 33 deletions

View file

@ -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 {