mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 15:12:26 +00:00
some changes with config.log.output
This commit is contained in:
@@ -60,7 +60,7 @@ func (c *Compositor) LoadConf(path string) error {
|
||||
v.SetDefault("updates.wanted_version", "latest-stable")
|
||||
v.SetDefault("log.json_format", "false")
|
||||
v.SetDefault("log.level", "info")
|
||||
v.SetDefault("log.output", "%stdout%")
|
||||
v.SetDefault("log.output", "%1%")
|
||||
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
return fmt.Errorf("error reading config: %w", err)
|
||||
|
||||
@@ -57,7 +57,7 @@ type Updates struct {
|
||||
type Log struct {
|
||||
JSON *bool `mapstructure:"json_format"`
|
||||
Level *string `mapstructure:"level"`
|
||||
OutPath any `mapstructure:"output"`
|
||||
OutPath *string `mapstructure:"output"`
|
||||
}
|
||||
|
||||
// ConfigEnv structure for environment variables
|
||||
|
||||
@@ -6,7 +6,6 @@ package logs
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
@@ -58,30 +57,14 @@ func SetupLogger(o *config.Log) (*slog.Logger, error) {
|
||||
handlerOpts.Level = slog.LevelInfo
|
||||
}
|
||||
|
||||
switch o.OutPath {
|
||||
case 1:
|
||||
switch *o.OutPath {
|
||||
case "_1STDout":
|
||||
writer = os.Stdout
|
||||
case 2:
|
||||
writer = os.Stderr
|
||||
case os.Stdout:
|
||||
writer = os.Stdout
|
||||
case os.Stderr:
|
||||
case "_2STDerr":
|
||||
writer = os.Stderr
|
||||
default:
|
||||
var path string
|
||||
switch v := o.OutPath.(type) {
|
||||
case string:
|
||||
path = v
|
||||
case int, int64, float64:
|
||||
path = fmt.Sprint(v)
|
||||
case fmt.Stringer:
|
||||
path = v.String()
|
||||
default:
|
||||
path = fmt.Sprint(v)
|
||||
}
|
||||
|
||||
logFile := &lumberjack.Logger{
|
||||
Filename: filepath.Join(path, "event.log"),
|
||||
Filename: filepath.Join(*o.OutPath, "event.log"),
|
||||
MaxSize: 10,
|
||||
MaxBackups: 5,
|
||||
MaxAge: 28,
|
||||
|
||||
Reference in New Issue
Block a user