-
Notifications
You must be signed in to change notification settings - Fork 109
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
[MM-19315] Replace old Logger with mlog.Logger (mattermost package) #130
[MM-19315] Replace old Logger with mlog.Logger (mattermost package) #130
Conversation
Refactored the logging system in both Android and Apple notification servers. Replaced `logger.Infof` with `logger.Info` for a more structured logging approach, using `mlog.String`, `mlog.Int`, and `mlog.Err` to provide additional context. This change enhances readability and allows for better log analysis.
The logging statements in the server and notification files have been refactored to improve readability. The changes include replacing `logger.Errorf` with `logger.Error` and using structured logging fields instead of string formatting. This makes it easier to understand the log messages and their associated data.
Switched from using Panic to Fatal in the server's error handling mechanism. This change ensures that any serious errors will cause the program to exit immediately, rather than just panicking and potentially leaving the server in an unstable state.
The logger type has been updated from *Logger to *mlog.Logger in the AndroidNotificationServer, AppleNotificationServer, and Server structures. This change also affects the NewAndroidNotificationServer, NewAppleNotificationServer functions where the logger parameter type is updated accordingly.
Refactored the ConfigPushProxy struct. Deprecated LogFileLocation, EnableConsoleLog, and EnableFileLog for backward compatibility. Introduced LoggingCfgFile and LoggingCfgJSON as replacements. No changes to other existing fields.
Removed the automatic enabling of console log when both console and file logs are disabled. Also, removed the creation and handling of log files within the configuration loading function. This simplifies the function by focusing it solely on loading configurations.
The main function has been updated to include a more robust logger initialization process. This includes error handling for the creation of a new logger, as well as its configuration. If no logging is defined, a default config (console output) is used. A separate function has been added to provide this default logging configuration. The server now also ensures that the logger is properly shut down when it's no longer needed.
Upgraded the Go version from 1.21 to 1.22 and updated various dependencies to their latest versions. This includes updates to firebase, gorilla handlers, mux, prometheus client_golang, common, golang.org/x/net and oauth2 among others. Also added new dependencies such as github.com/mattermost/mattermost/server/public and github.com/francoispqt/gojay.
Hello @willypuzzle, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. |
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.
Looks great! Just a couple of comments to discuss.
The default logging configuration has been refactored to support both console and file logging. The logic for generating the default config has been moved from main.go to a new file, server/logging.go. This change allows the application to dynamically choose between console or file logging based on the 'EnableFileLog' flag in the configuration.
Thank you @willypuzzle. I will be taking a look at this soon. |
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.
A couple more comments about tests.
This reverts commit 8e38a57.
Upgraded the Go version from 1.21 to 1.22 and updated various dependencies to their latest versions. Also, added new dependencies required for the project's functionality.
The Docker images for Go and Golint have been updated to newer versions. The new version of the Go image includes various performance improvements and bug fixes. Similarly, the Golint image has also been updated to include the latest linting rules and enhancements.
The logger initialization in various test files has been updated. Instead of using the NewLogger function, we are now using mlog.NewLogger(). This change affects android_notification_test.go, metrics_test.go, and server_test.go.
- Added error checks after initializing new loggers in various test functions to ensure no silent failures. - Simplified the condition check for enabling file logs by directly using the boolean value.
Introduced a new set of unit tests for the server's logging functionality. These tests cover various aspects such as escaping double quotes, default console log configuration, file log configuration and overall logging configuration. Also added a helper function to generate random strings for testing purposes.
The logging settings have been simplified and restructured. The previous console and file log enablement flags have been removed. Instead, a new approach has been introduced where the logging configuration is now handled through a dedicated config file or directly via JSON.
A new JSON configuration file for logging has been added. This includes settings for console type output, plain formatting, and color enabling. It also specifies minimum lengths for level and message, as well as the inclusion of caller information. Different log levels from debug to panic have been defined with corresponding IDs and optional color or stacktrace attributes.
The logger initialization and configuration process has been refactored for better code organization. The logic previously in the main function is now encapsulated within a new function, NewMlogLogger, in the server package. This change also includes updates to logging tests to accommodate the new structure.
This update includes several significant changes: - The release is compatible with all versions of Mattermost server and mobile. - Notably, Google Cloud Messaging (GCM) service has been deprecated as of April 10, 2018, and will be removed by April 11, 2019. Migration to Firebase Cloud Messaging (FCM) is necessary. - The old Logger system has been replaced with a new one. - Deprecated types EnableConsoleLog, EnableFileLog, and LogFileLocation from the config have been replaced. - Lastly, we've switched from go version 1.21 to go version 1.22 for improved performance and stability.
The README file has been updated to include a reference to the CHANGELOG. This will provide users with more detailed information about the changes made in each release.
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.
Great work! Just two minor comments.
/update-branch |
Error trying to update the PR. |
@toninis - Any idea why CI is not running for this PR? |
@agnivade no prob! ask the same, I'm happy to have practice with go! |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
/update-branch |
Error trying to update the PR. |
@willypuzzle - could you please update this branch with latest master and push again? Sorry for the delay. The person I pinged is on leave. |
@agnivade the PR's branch is just updated |
Can you push an empty commit? I want to re-trigger the CI flow for a fresh commit. |
I meant just an empty commit. You can do that by |
This reverts commit e35b0d6.
sorry, I didn't know it. |
Thanks, I will take it from here. |
@willypuzzle - Could you please merge with latest master and push again? This commit 93d8c3b should take care of the problem. |
Thanks for your patience @willypuzzle ! |
@agnivade Thanks to you! I always learn a lot from you all! |
Summary
This PR replace the old Logger with the more modern mlog.Logger.
Ticket Link
mattermost/mattermost#14407
Release note:
Added LogFormat option, possible values are
plain
orjson
(default value:plain
)