Skip to content
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

Replace System.out.println references with SLF4j #79

Closed
Tracked by #36
adamkorynta opened this issue Dec 13, 2023 · 3 comments · Fixed by #121
Closed
Tracked by #36

Replace System.out.println references with SLF4j #79

adamkorynta opened this issue Dec 13, 2023 · 3 comments · Fixed by #121
Milestone

Comments

@adamkorynta
Copy link
Contributor

Component to be refactored
Replace calls to System.out.println to use JUL logging instead.

Purpose of refactoring
Using Java Util Logging is more maintainable than using System.out.println for several reasons. Firstly, Java Util Logging provides different logging levels (SEVERE, WARNING, INFO, etc.), which allows for more granular control over what information is logged and when. This is not possible with System.out.println, which outputs everything regardless of its importance. Secondly, Java Util Logging supports output to different targets, not just the console, but also file systems, sockets, etc., and can be easily configured to change the output target. Thirdly, Java Util Logging supports formatting of log messages, which can make the logs easier to read and parse. Lastly, using a logging framework like Java Util Logging can improve performance, as it can be configured to log messages asynchronously. On the other hand, using System.out.println can slow down an application because it's a synchronous operation.

Proposed method
SonarCloud has identified quite a few calls that need to be rerouted . They should all be replaced, though the effort might be too high to do at once so this might be accomplished in several efforts or when surrounding code is updated.

Additional context
As a stopgap HEC has been using Flogger (Google's fluent logger API) to reroute all System.out calls to JUL and whenever code lines are updated surrounding the System.out code, they are replaced with JUL calls.

@MikeNeilson
Copy link
Collaborator

I think OpenDCS has settle on slf4j.

opendcs/opendcs#394
and
opendcs/opendcs#161

Probably good to get feedback from @opendcs/opendcs-core-devs

A lot of the libraries we use (I plan to excise the hec libraries for various reasons over time unless absolutely required) already use slf4j as the facade anyways.

@adamkorynta
Copy link
Contributor Author

Good point, there are about the same number of references in the codebase to JUL as there are System.out (~>300 total), so double the effort to switch everything to slf4j.

@MikeNeilson
Copy link
Collaborator

Since we'll likely just be using JUL (or more correctly juli) for logging anyways, we really only need to start with System.(out|err).println calls.

But I'm certainly not going to stop you if you want to do more. Lot easier to do here than in the main code.

@adamkorynta adamkorynta mentioned this issue Dec 19, 2023
1 task
@adamkorynta adamkorynta changed the title Replace System.out.println references with JUL Replace System.out.println references with SLF4j Jan 22, 2024
@adamkorynta adamkorynta added this to the Future Work milestone Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants