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"`
|
DebugEndpoints bool `yaml:"debug_endpoints"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultConfig = Config{
|
var defaultFileWriter = zeroconfig.WriterConfig{
|
||||||
Web: WebConfig{
|
Type: zeroconfig.WriterTypeFile,
|
||||||
ListenAddress: "localhost:29325",
|
Format: "json",
|
||||||
},
|
FileConfig: zeroconfig.FileConfig{
|
||||||
Logging: zeroconfig.Config{
|
Filename: "",
|
||||||
MinLevel: ptr.Ptr(zerolog.TraceLevel),
|
MaxSize: 100 * 1024 * 1024,
|
||||||
Writers: []zeroconfig.WriterConfig{{
|
MaxBackups: 10,
|
||||||
Type: zeroconfig.WriterTypeStdout,
|
|
||||||
Format: zeroconfig.LogFormatPrettyColored,
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeDefaultConfig() Config {
|
||||||
|
return Config{
|
||||||
|
Web: WebConfig{
|
||||||
|
ListenAddress: "localhost:29325",
|
||||||
|
},
|
||||||
|
Logging: zeroconfig.Config{
|
||||||
|
MinLevel: ptr.Ptr(zerolog.DebugLevel),
|
||||||
|
Writers: []zeroconfig.WriterConfig{{
|
||||||
|
Type: zeroconfig.WriterTypeStdout,
|
||||||
|
Format: zeroconfig.LogFormatPrettyColored,
|
||||||
|
}, defaultFileWriter},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (gmx *Gomuks) LoadConfig() error {
|
func (gmx *Gomuks) LoadConfig() error {
|
||||||
file, err := os.Open(filepath.Join(gmx.ConfigDir, "config.yaml"))
|
file, err := os.Open(filepath.Join(gmx.ConfigDir, "config.yaml"))
|
||||||
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)
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue