Use configured logging target

This commit is contained in:
Ingo Oppermann
2023-01-03 11:54:48 +01:00
parent f472fe150f
commit 4a12b0293f
2 changed files with 42 additions and 2 deletions

View File

@@ -70,6 +70,27 @@ func doMigration(logger log.Logger, configstore cfgstore.Store) error {
return fmt.Errorf("the configuration contains errors: %v", messages)
}
var writer log.Writer
if cfg.Log.Target.Output == "stdout" {
writer = log.NewConsoleWriter(
os.Stdout,
true,
)
} else if cfg.Log.Target.Output == "file" {
writer = log.NewFileWriter(
cfg.Log.Target.Path,
log.NewJSONFormatter(),
)
} else {
writer = log.NewConsoleWriter(
os.Stderr,
true,
)
}
logger = logger.WithOutput(writer)
ff, err := ffmpeg.New(ffmpeg.Config{
Binary: cfg.FFmpeg.Binary,
})

View File

@@ -38,8 +38,6 @@ func doImport(logger log.Logger, configstore cfgstore.Store) error {
logger = log.New("")
}
logger.Info().Log("Database import")
cfg := configstore.Get()
// Merging the persisted config with the environment variables
@@ -65,6 +63,27 @@ func doImport(logger log.Logger, configstore cfgstore.Store) error {
return fmt.Errorf("the configuration contains errors: %v", messages)
}
var writer log.Writer
if cfg.Log.Target.Output == "stdout" {
writer = log.NewConsoleWriter(
os.Stdout,
true,
)
} else if cfg.Log.Target.Output == "file" {
writer = log.NewFileWriter(
cfg.Log.Target.Path,
log.NewJSONFormatter(),
)
} else {
writer = log.NewConsoleWriter(
os.Stderr,
true,
)
}
logger = logger.WithOutput(writer)
logger.Info().Log("Checking for database ...")
// Check if there's a v1.json from the old Restreamer