Fix missing default logFile config

This commit is contained in:
Jan-Lukas Else 2021-12-27 21:47:12 +01:00
parent 251fdc07e5
commit 61cecf8454
3 changed files with 12 additions and 1 deletions

View File

@ -398,6 +398,7 @@ func createDefaultConfig() *config {
Server: &configServer{
Port: 8080,
PublicAddress: "http://localhost:8080",
LogFile: "data/access.log",
},
Db: &configDb{
File: "data/db.sqlite",

View File

@ -9,7 +9,7 @@ import (
)
func (a *goBlog) initHTTPLog() (err error) {
if !a.cfg.Server.Logging {
if !a.cfg.Server.Logging || a.cfg.Server.LogFile == "" {
return nil
}
a.logf, err = rotatelogs.New(

View File

@ -12,6 +12,16 @@ import (
"github.com/stretchr/testify/require"
)
func Test_httpLogsConfig(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
_ = app.initConfig()
assert.Equal(t, false, app.cfg.Server.Logging)
assert.Equal(t, "data/access.log", app.cfg.Server.LogFile)
}
func initTestHttpLogs(logFile string) (http.Handler, error) {
app := &goBlog{