-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add Generic Log functions with level via argument #863
Conversation
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.
Hit Approve too fast.
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.
@lugray Do you only need Log()
on Entry
? I would think you'd want it on Logger
?
Maybe some more context in the description would help -- some examples.
In my case I did only need it on An example of why you'd want this, and where I use it: const ignoreError logrus.Level = math.MaxInt32
func runAndLogGitCmd(ctx context.Context, cmd shell.Supervisor, defaultLevel logrus.Level, levelOverrides map[string]logrus.Level) (stdout []byte, err error) {
stdout, stderr, err := cmd.RunAndGetOutput()
if err == nil {
return stdout, nil
}
gitErr := parseGitCmdError(string(stderr), err)
level := defaultLevel
if levelOverrides != nil {
if l, ok := levelOverrides[gitErr.ID()]; ok {
level = l
}
}
if level == ignoreError {
return stdout, nil
}
log(ctx, gitErr).WithFields(gitErr.LogFields()).Log(level, "error while running git command")
return stdout, gitErr
} Some git errors in our app should be fully ignored, others should be downgraded to |
@lugray Maybe add a |
Added test - thanks for the review on this. |
…/logrus Apparently due to this [merge request](sirupsen/logrus#863) another level to stacktrace was introduced. So if we intend to skip it by default we have to increase default number of skips in our configuration.
Add Generic Log functions with level via argument
I wanted to be able to use
Log
with a variable level, and it seemed like I should addLogf
andLogln
if I was going to addLog
.