Skip to content

Conversation

@sima-zhu
Copy link
Contributor

The PR is to have more checking on the log level.
We agreed to check

  • slf4j binding as our log level.
  • If slf4j configuration is not set, we will read from env.
  • If both are not present, we will set log level to NOT_SET.
    I have implemented src code only for team to review.

TODO: Will add more unit tests for code coverage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogLevel is in an implementation package and will need to be moved to public package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is for reviewing the code flow, not finished yet.
Will merge the changes in PR: #6886.
Also, will fix the tests after merging.

@alzimmermsft
Copy link
Member

Need to update some tests or change their setup based on this change. If you want to add more tests around handling when SLF4J has a binder and which levels can be logged at you can look at the ClientLoggerTests which setup the logger with a given level of support and here is the conversion of environment log level name to level https://github.com/qos-ch/slf4j/blob/master/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java#L145.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the binder still be checked? That way if an SLF4J binding exists but all logging levels are disabled we won't default into the environment configuration and instead wouldn't log anything as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my testing, if there is some other logging binding to SLF4J, logger.isDebugEnabled() will reflect the log level set by user. So if log4j set log level to info, then the clientLogger logger.canLogAtLevel(LogLevel.INFO) returns true.

Also, Binder check API is inside of slf4j-simple pkg which asks to introduce slf4j impl library to src code. This is not ideal as you comment above.

@sima-zhu sima-zhu requested a review from alzimmermsft January 7, 2020 19:48
logger = LoggerFactory.getLogger(className);
System.setProperty("java.util.logging.config.file",
ClientLogger.class.getClassLoader().getResource("logging.properties").getPath());
defaultLogger = java.util.logging.Logger.getLogger(className);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't overwrite a system property. Use another means to configure the logger. Also, don't create a default logger unless necessary - you're paying the price here to create two loggers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can initial it into log method. Try to figure out if we can set the logLevel during runtime.

@sima-zhu
Copy link
Contributor Author

sima-zhu commented Jan 8, 2020

Closed the PR as we agreed to use Sys.out for now.

@sima-zhu sima-zhu closed this Jan 8, 2020
@sima-zhu sima-zhu deleted the slf4j_env branch July 13, 2020 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants