Zap logger for Casbin

Clone this repo:
  1. f8db1b9 feat: fix compatibility with Casbin v3.7.0's new logger interface (#10) by Io Wayfarer · 9 weeks ago master v2.5.0
  2. cb73bb5 feat: upgrade CI workflows to Node.js 20 (#18) by Yang Luo · 9 weeks ago v2.4.0
  3. c649693 feat: fix duplicate CI runs on pull requests (#16) by Yang Luo · 9 weeks ago v2.3.0
  4. d1a5a35 feat: fix CI: use go install for goveralls instead of go get by Yang Luo · 9 weeks ago v2.2.0
  5. 871ffed docs: fix dead links (#9) by QingKai Hao · 2 years, 7 months ago

Installation

go get github.com/casbin/zap-logger

How to use it

You could import the zap-logger module like:

import (
    zaplogger "github.com/casbin/zap-logger/v3"
    "github.com/casbin/casbin/v3"
)

You could let your enforcer use this logger when you first initialize your enforcer like:

e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)
e.EnableLog(true)
e.SetLogger(zaplogger.NewLogger(true, true))

or with and existing zap instance.

logger := zaplogger.NewLoggerByZap(yourZapLogger, true)
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)
e.EnableLog(true)
e.SetLogger(logger)

And the method NewLogger have two params: enabled and jsonEncode, you could initialize logger's log status and decide whether to output information with json encoded or not.

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.