-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integrate logrus logging to rego interpreter package #1730
base: main
Are you sure you want to change the base?
Conversation
afc087a
to
9e77b73
Compare
Looks good, thanks for doing this work! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the logger interface
probably something we should do for the whole repo so we can replace logrus with zap or something a lot easier
return LogLevel(atomic.LoadInt32((*int32)(&ll.level))) | ||
} | ||
|
||
type InterpreterLogger interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theres a structured logger thats being added to the std library that defines this and has a bunch of convince functions:
https://pkg.go.dev/golang.org/x/exp/slog#Handler
i think youd just need to define an implementation for the handler, then the slog.New(...)
should work and give you all the logging functions you need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looked more into this. problem is that interpreter defines rather different "levels" and we may need to decide how we want to map them? In general slog seems like a good replacement for logrus.
var _ InterpreterLogger = (*logrusLogger)(nil) | ||
|
||
func NewFileLogger(path string, level LogLevel) (InterpreterLogger, error) { | ||
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to set the log file to be 0644
so that it can only be written to by the owning user?
Add a new InterpreterLogger interface and introduce 2 implementations: fileLogger and logrusLogger. File logger behaves the same way as the previous implementation, except that it uses logrus, rather than go built-in. Logrus logger implementation uses hcsshim's logrus wrappers. Signed-off-by: Maksim An <maksiman@microsoft.com>
9e77b73
to
ba10efd
Compare
Add a new InterpreterLogger interface and introduce 2 implementations: fileLogger and logrusLogger. File logger behaves the same way as the previous implementation, except that it uses logrus, rather than go built-in. Logrus logger implementation uses hcsshim's logrus wrappers.