-
Notifications
You must be signed in to change notification settings - Fork 54
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 log level and format configuration options for services #567
Conversation
This is great, thank you for working on it! If you are thinking having different flags for What do you mean with To update the documentation, clone the repository https://github.com/jmpsec/osctrl-docs, update the markdown in the |
@@ -1046,8 +1085,13 @@ func main() { | |||
} | |||
app.Action = cliAction | |||
if err := app.Run(os.Args); err != nil { | |||
log.Fatal().Msgf("app.Run error: %v", err) |
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.
It is preferable to use Fatal()
than to print the error and call exit, because closing writers and flushing buffers. See the implementation of Fatal()
in zerolog
:
// Fatal starts a new message with fatal level. The os.Exit(1) function
// is called by the Msg method, which terminates the program immediately.
//
// You must call Msg on the returned event in order to send the event.
func (l *Logger) Fatal() *Event {
return l.newEvent(FatalLevel, func(msg string) {
if closer, ok := l.w.(io.Closer); ok {
// Close the writer to flush any buffered message. Otherwise the message
// will be lost as os.Exit() terminates the program immediately.
closer.Close()
}
os.Exit(1)
})
}
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 think we cannot use Fatal()
because the zerolog is not initialized.
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.
We will initialize the log after reading all the parameters.
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 think we can use the same parameters in osctrl-tls
for consistency, but there are some changes needed, thank you!
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.
@javuto I have updated the code according to your comments, could you please take another look.
@@ -1046,8 +1085,13 @@ func main() { | |||
} | |||
app.Action = cliAction | |||
if err := app.Run(os.Args); err != nil { | |||
log.Fatal().Msgf("app.Run error: %v", err) |
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 think we cannot use Fatal()
because the zerolog is not initialized.
@@ -1046,8 +1085,13 @@ func main() { | |||
} | |||
app.Action = cliAction | |||
if err := app.Run(os.Args); err != nil { | |||
log.Fatal().Msgf("app.Run error: %v", err) |
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.
We will initialize the log after reading all the parameters.
Introduce configuration options for log level and format in services, allowing customization of logging behavior. This change enhances the flexibility of logging by enabling different log levels and formats through command-line flags and environment variables.
The change was made for admin and api. For tls, I would like to discuss a better naming convention:
Also, the code are highly duplicated and I would like to remove the duplication.
For documentation, do you know where should update these configuration options?