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
Fatal should deterministically calculate the POSIX return code #1086
Comments
Hi there 👋 thank you for the contribution, but this is a breaking change. That being said, you should be able to change the behavior of |
+1 on the backwards compatibility. However, the |
I think we could change the |
I updated the #1088 to be backward compatible, by adding new The new action will calculate the |
@cardil, thanks for the report and the contribution! We realize that this is something that might deserve a customizable. Unfortunately, the current implementation in #1088 isn't fit to merge because:
I think I would lean more towards a variant where we support an arbitrary This requires a little care to do in a backwards compatible way but, @prashantv @sywhang @cardil, what do you think of something like the following? package zap
func WithFatalHook(zapcore.CheckWriteHook) Option
package zapcore
type CheckWriteHook interface {
OnWrite(*CheckedEntry, []Field)
}
func (*CheckedEntry) After(Entry, CheckWriteHook) *CheckedEntry
To make the deprecation easy, zapcore.CheckWriteAction will implement the CheckWriteHook interface so a user will be able to do |
This adds a new WithFatalHook option that allows specifying arbitrary behavior overrides messages logged with FatalLevel. This supersedes the previous OnFatal option that relied on a CheckWriteAction enum. The enum is replaced by a CheckWriteHook--a hook that runs after write. Refs #1086 Co-authored-by: Sung Yoon Whang <sungyoon@uber.com> Co-authored-by: Abhinav Gupta <abg@uber.com>
Thanks for the PR @cardil, and thanks @sywhang for the tweaks. Hope this helps, and thanks again for your contribution. |
The Fatal method is calling
os.Exit(1)
regardless of a message. This isn't the best UX choice. The POSIX return code could be used for quick assessment about a process failure. When the retcode is always equal1
for any error, this can't be utilized.Tools like Docker or Kubernetes report back the return code of the process. By using a deterministic algorithm to calculate the POSIX return code, a quick debugging is possible. Users could indicate if the process is failing because of the same reason, without looking into logs.
The best would be to rely on Fatal's message or on an error object if it's attached as a Field.
The text was updated successfully, but these errors were encountered: