config: enable file logging by default

This commit is contained in:
Tulir Asokan 2024-11-18 00:06:40 +02:00
parent 0bf4452e6e
commit 3a34576d88
2 changed files with 24 additions and 11 deletions

View file

@ -44,17 +44,29 @@ type WebConfig struct {
DebugEndpoints bool `yaml:"debug_endpoints"` DebugEndpoints bool `yaml:"debug_endpoints"`
} }
var defaultConfig = Config{ var defaultFileWriter = zeroconfig.WriterConfig{
Type: zeroconfig.WriterTypeFile,
Format: "json",
FileConfig: zeroconfig.FileConfig{
Filename: "",
MaxSize: 100 * 1024 * 1024,
MaxBackups: 10,
},
}
func makeDefaultConfig() Config {
return Config{
Web: WebConfig{ Web: WebConfig{
ListenAddress: "localhost:29325", ListenAddress: "localhost:29325",
}, },
Logging: zeroconfig.Config{ Logging: zeroconfig.Config{
MinLevel: ptr.Ptr(zerolog.TraceLevel), MinLevel: ptr.Ptr(zerolog.DebugLevel),
Writers: []zeroconfig.WriterConfig{{ Writers: []zeroconfig.WriterConfig{{
Type: zeroconfig.WriterTypeStdout, Type: zeroconfig.WriterTypeStdout,
Format: zeroconfig.LogFormatPrettyColored, Format: zeroconfig.LogFormatPrettyColored,
}}, }, defaultFileWriter},
}, },
}
} }
func (gmx *Gomuks) LoadConfig() error { func (gmx *Gomuks) LoadConfig() error {
@ -62,7 +74,7 @@ func (gmx *Gomuks) LoadConfig() error {
if err != nil && !errors.Is(err, os.ErrNotExist) { if err != nil && !errors.Is(err, os.ErrNotExist) {
return err return err
} }
gmx.Config = defaultConfig gmx.Config = makeDefaultConfig()
changed := false changed := false
if file != nil { if file != nil {
err = yaml.NewDecoder(file).Decode(&gmx.Config) err = yaml.NewDecoder(file).Decode(&gmx.Config)

View file

@ -146,6 +146,7 @@ func (gmx *Gomuks) InitDirectories() {
exerrors.PanicIfNotNil(os.MkdirAll(gmx.TempDir, 0700)) exerrors.PanicIfNotNil(os.MkdirAll(gmx.TempDir, 0700))
exerrors.PanicIfNotNil(os.MkdirAll(gmx.DataDir, 0700)) exerrors.PanicIfNotNil(os.MkdirAll(gmx.DataDir, 0700))
exerrors.PanicIfNotNil(os.MkdirAll(gmx.LogDir, 0700)) exerrors.PanicIfNotNil(os.MkdirAll(gmx.LogDir, 0700))
defaultFileWriter.FileConfig.Filename = filepath.Join(gmx.LogDir, "gomuks.log")
} }
func (gmx *Gomuks) SetupLog() { func (gmx *Gomuks) SetupLog() {