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

Loggable and Log4J2 (and Dropwizard): Does not Apply Package/Class Logger Level #253

Open
VincenzoFerme opened this issue Nov 11, 2017 · 2 comments

Comments

@VincenzoFerme
Copy link

Hi, thank you for this fantastic library, I am using it for logging in a Dropwizard service.

I think that @Loggable does not pick the package/class level if using Log4J2 in a Dropwizard service (and maybe also in other contexts).

I attach to this issue (jcabi-aspects-loggable-log2j2-level.zip) a simple Dropwizard example (built with Maven) service to reproduce the behaviour I experienced. The behaviour is the following:

  1. Configure Log4J2 as follow in a log4j2.yml file:
Configuration:
  name: Jcabi Aspects Log Level Service

  Properties:
    Property:
      name: root-log-level
      value: INFO

  Appenders:
    Console:
      PatternLayout:
        pattern: '%d{yyyy-MMM-dd HH:mm:ss.SSS/zzz a}{GMT} [%logger{36}:%t:%L] %-5level - %msg%n'
      name: Console
      target: SYSTEM_OUT
  Loggers:
    Root:
      level: ${root-log-level}
      AppenderRef:
        - ref: Console
    Logger:
      - name: "jcabi.aspects.loggable.log.level.api"
        level: TRACE
        AppenderRef:
          - ref: Console
    Logger:
      - name: "org.hibernate.validator"
        level: ERROR
        AppenderRef:
          - ref: Console

as you can see the root log level is INFO, and I set a custom logger with a TRACE log level for the package "jcabi.aspects.loggable.log.level.api".
2. Set the log level of the @Loggable annotation to TRACE.
3. Run the service (e.g., with java -jar target/example.jar server configuration.yml), make a call on the defined API (e.g., using curl -X GET 127.0.0.1:8080/v1/example) and you are NOT going to see the Loggable logs.

Now:

  1. Change the log4j2.yml file as follows, thus setting the root log level to TRACE, the same log level as the @Loggable annotation:
Configuration:
  name: Jcabi Aspects Log Level Service

  Properties:
    Property:
      name: root-log-level
      value: TRACE

  Appenders:
    Console:
      PatternLayout:
        pattern: '%d{yyyy-MMM-dd HH:mm:ss.SSS/zzz a}{GMT} [%logger{36}:%t:%L] %-5level - %msg%n'
      name: Console
      target: SYSTEM_OUT
  Loggers:
    Root:
      level: ${root-log-level}
      AppenderRef:
        - ref: Console
    Logger:
      - name: "jcabi.aspects.loggable.log.level.api"
        level: TRACE
        AppenderRef:
          - ref: Console
    Logger:
      - name: "org.hibernate.validator"
        level: ERROR
        AppenderRef:
          - ref: Console
  1. Run the service (e.g., with java -jar target/example.jar server configuration.yml), make a call on the defined API (e.g., using curl -X GET 127.0.0.1:8080/v1/example) and you are going to see the Loggable logs.

I think that Loggable is only picking the root log level settings, not the package/class log level.

Let me know if I can improve the explanation, and if you are aware of this issue and know how to solve it or I made some mistake in setting up Loggable in the service.

@0crat
Copy link

0crat commented Nov 11, 2017

@yegor256 please, pay attention to this issue

@yegor256
Copy link
Member

@VincenzoFerme this seems to be a bug, but I can't really understand what is the cause of it. Maybe you can contribute with a pull request? The entire functionality is here: https://github.com/jcabi/jcabi-aspects/blob/master/src/main/java/com/jcabi/aspects/aj/MethodLogger.java

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

No branches or pull requests

3 participants