Add logger.

This commit is contained in:
Yang Luo 2021-05-07 20:51:29 +08:00
parent 8a4311c85c
commit a24665714a
2 changed files with 16 additions and 2 deletions

View File

@ -16,6 +16,7 @@ package main
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/plugins/cors"
"github.com/casdoor/casdoor/authz"
"github.com/casdoor/casdoor/controllers"
@ -54,5 +55,12 @@ func main() {
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365
//beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode
err := logs.SetLogger("file", `{"filename":"logs/casdoor.log","maxdays":99999}`)
if err != nil {
panic(err)
}
logs.SetLevel(logs.LevelInformational)
logs.SetLogFuncCall(false)
beego.Run()
}

View File

@ -102,8 +102,14 @@ func AuthzFilter(ctx *context.Context) {
isAllowed := authz.IsAllowed(subOwner, subName, method, urlPath, objOwner, objName)
fmt.Printf("subOwner = %s, subName = %s, method = %s, urlPath = %s, obj.Owner = %s, obj.Name = %s, isAllowed = %v\n",
subOwner, subName, method, urlPath, objOwner, objName, isAllowed)
result := "deny"
if isAllowed {
result = "allow"
}
logLine := fmt.Sprintf("subOwner = %s, subName = %s, method = %s, urlPath = %s, obj.Owner = %s, obj.Name = %s, result = %s",
subOwner, subName, method, urlPath, objOwner, objName, result)
fmt.Println(logLine)
util.LogInfo(ctx, logLine)
if !isAllowed {
denyRequest(ctx)
}