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

Hard to find how to define logging level for system backend #160

Open
igorgatis opened this issue Apr 27, 2020 · 10 comments
Open

Hard to find how to define logging level for system backend #160

igorgatis opened this issue Apr 27, 2020 · 10 comments
Labels
P3 type=documentation Documentation that is other than for an API

Comments

@igorgatis
Copy link

I spent a fair amount of time trying to find how to set logging level for system backend. I failed and I gave up. Is there is a knob for that, mind making it easier to find or state it is not possible for system backend?

@hagbard
Copy link
Contributor

hagbard commented Apr 27, 2020

The system backend uses JDK logger, so just set the log level of the equivalently named JDK logger or parent logger. Using a logging.properties file is best.

http://tutorials.jenkov.com/java-logging/configuration.html

Currently Flogger is agnostic to how log levels are set and deliberately doesn't offer an API (since a different backend might treat log levels completely differently).At some point I might rethink what "controlling logging" means, but that's a very big effort and I don't have time, so for now you have to set logging levels according to the chosen backend in the system.

This makes it hard for random classes to change logging configuration programmatically, but personally I think that's something they should not be doing anyway (logging config should be set up by the outer logic in an application or via system properties, where the logger backend is known).

@igorgatis
Copy link
Author

Thanks! Does it make sense to point that in the easy-to-find documentation?

@hagbard
Copy link
Contributor

hagbard commented Apr 27, 2020

Yeah, that's a good point, I'll add something to the top level docs. It's always hard to remember to document the things your code doesn't do :)

@cpovirk cpovirk added P3 type=documentation Documentation that is other than for an API labels Apr 27, 2020
@dpursehouse
Copy link

I'm also having a hard time figuring out how to configure flogger properly. I've migrated a huge codebase from slf4j to flogger, and for some reason when running tests none of the debug logs are being emitted.

Code that previously looked like this just worked:

private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
...
logger.debug("some useful debug info");

but after replacing with:

private static final FluentLogger logger = FluentLogger.forEnclosingClass();
...
logger.atFine().log("some useful debug info");

the logs are not emitting when running tests. Only logs atInfo, atWarning and atSevere are coming out.

Same issue with tests in junit and testng.

@hagbard
Copy link
Contributor

hagbard commented May 1, 2020

Which logging backed are you using? The JDK logger based "system" backend uses INFO as the default log level, so it's expected that "fine" logging will be suppressed unless you use that standard JDK logging configuration mechanisms to change that.

@dpursehouse
Copy link

It's using log4j as far as I know. This is also reproducible on the Gerrit project. See this issue.

Gerrit sets up the log like this, using Apache log4j's log manager:

  public static void configureLogging() {
    LogManager.resetConfiguration();

    PatternLayout layout = new PatternLayout();
    layout.setConversionPattern("%-5p %c %x: %m%n");

    ConsoleAppender dst = new ConsoleAppender();
    dst.setLayout(layout);
    dst.setTarget("System.err");
    dst.setThreshold(Level.DEBUG);
    dst.activateOptions();

    Logger root = LogManager.getRootLogger();
    root.removeAllAppenders();
    root.addAppender(dst);

    LOG_LEVELS.entrySet().stream().forEach(e -> getLogger(e.getKey()).setLevel(e.getValue()));
  }

Logs using flogger's atFine() don't emit, but logs using slf4j's debug() do.

I suspect it's something missing (or wrong) in the configuration, but I'm not really sure where to look.

@hagbard
Copy link
Contributor

hagbard commented May 1, 2020

If it's using Log4J, then I'm afraid I can't help you. The Log4J backend is community supported and not something I understand at all really. What I can tell you is that the "core" Flogger code never tries to decide whether to log or not, it always just calls the backend to get that.

My guess is still that it's actually using the JDK backend, since the observed changes in behaviour fit that idea exactly.

@dpursehouse
Copy link

I've just posted an update on that issue with some more findings. It looks like the settings that are done by the configureLogging method are not effective for flogger.

@hagbard
Copy link
Contributor

hagbard commented May 1, 2020

As I said, if it's using log4J, then it's a log4J backend bug (which I can't really help with) and if it's using the JDK logger backend then it's expected behaviour (since you aren't doing anything special to enable "fine" logging).

Why not just run the code in a debugger and see at what point a log statement is "dropped", and which classes are being loaded/used in the backend? This won't be hard to track down.

@dpursehouse
Copy link

The issue with Gerrit has been fixed by @davido
As I suspected, it was something missing in the configuration of the logger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 type=documentation Documentation that is other than for an API
Projects
None yet
Development

No branches or pull requests

4 participants