diff --git a/conf/app.conf b/conf/app.conf index 72d1e3ce..0bab2cd9 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -21,3 +21,4 @@ isDemoMode = false batchSize = 100 ldapServerPort = 389 quota = {"organization": -1, "user": -1, "application": -1, "provider": -1} +logConfig = {"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"} \ No newline at end of file diff --git a/conf/conf_test.go b/conf/conf_test.go index 4062bc12..da97de92 100644 --- a/conf/conf_test.go +++ b/conf/conf_test.go @@ -109,3 +109,19 @@ func TestGetConfigQuota(t *testing.T) { assert.Equal(t, scenery.expected, quota) } } + +func TestGetConfigLogs(t *testing.T) { + scenarios := []struct { + description string + expected string + }{ + {"Default log config", `{"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"}`}, + } + + err := beego.LoadAppConfig("ini", "app.conf") + assert.Nil(t, err) + for _, scenery := range scenarios { + quota := GetConfigString("logConfig") + assert.Equal(t, scenery.expected, quota) + } +} diff --git a/main.go b/main.go index 1b202250..ede864bc 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { beego.BConfig.WebConfig.Session.SessionCookieLifeTime = 3600 * 24 * 30 // beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode - err := logs.SetLogger("file", `{"filename":"logs/casdoor.log","maxdays":99999,"perm":"0770"}`) + err := logs.SetLogger(logs.AdapterFile, conf.GetConfigString("logConfig")) if err != nil { panic(err) }