diff --git a/config.go b/config.go index cc2607e..4b4fb7e 100644 --- a/config.go +++ b/config.go @@ -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", diff --git a/httpLogs.go b/httpLogs.go index 5ee3a20..da1b0e6 100644 --- a/httpLogs.go +++ b/httpLogs.go @@ -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( diff --git a/httpLogs_test.go b/httpLogs_test.go index 48f8f33..fefd00f 100644 --- a/httpLogs_test.go +++ b/httpLogs_test.go @@ -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{