diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-04 17:03:21 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-04 17:03:21 -0600 |
| commit | 7a9de18ccec27dfa63e1b8076da0724b3cdd41ee (patch) | |
| tree | d6d27740c363da3510a732e831b71fa9e8ef85a4 /pkg/policies | |
| parent | 0fc2735be3e2884bacfb17718d053d368965c8b2 (diff) | |
refactor: switch to zerolog logger
Diffstat (limited to 'pkg/policies')
| -rw-r--r-- | pkg/policies/init.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/pkg/policies/init.go b/pkg/policies/init.go index 42a2322..f5225a9 100644 --- a/pkg/policies/init.go +++ b/pkg/policies/init.go @@ -5,11 +5,13 @@ import ( _ "embed" "fmt" "io/fs" + "os" "strings" "github.com/cedar-policy/cedar-go" "github.com/cedar-policy/cedar-go/types" - xlog "gitlab.com/mokhax/spike/pkg/log" + "github.com/rs/zerolog" + "github.com/xlgmokha/x/pkg/log" ) //go:embed *.cedar *.json @@ -17,6 +19,7 @@ var files embed.FS var All *cedar.PolicySet = cedar.NewPolicySet() var Entities cedar.EntityMap = cedar.EntityMap{} +var Logger *zerolog.Logger = log.New(os.Stderr, log.Fields{"pkg": "policies"}) func init() { err := fs.WalkDir(files, ".", func(path string, d fs.DirEntry, err error) error { @@ -56,7 +59,7 @@ func init() { }) if err != nil { - xlog.Default.Printf("error: %v\n", err) + Logger.Err(err) } } @@ -65,14 +68,11 @@ func Allowed(request cedar.Request) bool { fmt.Printf("%v: %v -> %v %v%v\n", ok, request.Principal, request.Action.ID, request.Context.Map(), request.Resource.ID) if len(diagnostic.Errors) > 0 { - for err := range diagnostic.Errors { - xlog.Default.Printf("%v\n", err) - } + log.New(os.Stderr, log.Fields{"errors": diagnostic.Errors}) + Logger.Error().Fields(log.Fields{"errors": diagnostic.Errors}.ToMap()) } if len(diagnostic.Reasons) > 0 { - for reason := range diagnostic.Reasons { - xlog.Default.Printf("%v\n", reason) - } + Logger.Warn().Fields(log.Fields{"reasons": diagnostic.Reasons}.ToMap()) } return ok == types.Allow } |
