forked from Mirrors/gomuks
config: enable file logging by default
This commit is contained in:
parent
0bf4452e6e
commit
3a34576d88
2 changed files with 24 additions and 11 deletions
|
@ -44,25 +44,37 @@ type WebConfig struct {
|
|||
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{
|
||||
ListenAddress: "localhost:29325",
|
||||
},
|
||||
Logging: zeroconfig.Config{
|
||||
MinLevel: ptr.Ptr(zerolog.TraceLevel),
|
||||
MinLevel: ptr.Ptr(zerolog.DebugLevel),
|
||||
Writers: []zeroconfig.WriterConfig{{
|
||||
Type: zeroconfig.WriterTypeStdout,
|
||||
Format: zeroconfig.LogFormatPrettyColored,
|
||||
}},
|
||||
}, defaultFileWriter},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (gmx *Gomuks) LoadConfig() error {
|
||||
file, err := os.Open(filepath.Join(gmx.ConfigDir, "config.yaml"))
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
gmx.Config = defaultConfig
|
||||
gmx.Config = makeDefaultConfig()
|
||||
changed := false
|
||||
if file != nil {
|
||||
err = yaml.NewDecoder(file).Decode(&gmx.Config)
|
||||
|
|
|
@ -146,6 +146,7 @@ func (gmx *Gomuks) InitDirectories() {
|
|||
exerrors.PanicIfNotNil(os.MkdirAll(gmx.TempDir, 0700))
|
||||
exerrors.PanicIfNotNil(os.MkdirAll(gmx.DataDir, 0700))
|
||||
exerrors.PanicIfNotNil(os.MkdirAll(gmx.LogDir, 0700))
|
||||
defaultFileWriter.FileConfig.Filename = filepath.Join(gmx.LogDir, "gomuks.log")
|
||||
}
|
||||
|
||||
func (gmx *Gomuks) SetupLog() {
|
||||
|
|
Loading…
Add table
Reference in a new issue