mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Add logger.
This commit is contained in:
parent
8a4311c85c
commit
a24665714a
8
main.go
8
main.go
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user