1

I have a clean maven project and using lombok with this dependencies in my pom:

Edit: here is a sample project with the configurations I'm listing so you can take a look at it.

        <!--region Lombok Configuration -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.8.0-beta2</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <type>jar</type>
        </dependency>
        <!-- endregion -->

And 4 duplicated files placed in /src and /src/main/resources each:

  1. slf4j.properties=
  2. log4j.properties:
log4j.rootLogger=ERROR,stdout
log4j.logger.com.myorg=ERROR
log4j.logger.com.myorg.internal.myproj=ERROR

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n
  1. simplelogger.properties
org.slf4j.simpleLogger.defaultLogLevel=ERROR
  1. logback.xml
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<root level="error">
    <appender-ref ref="STDOUT" />
</root>
</configuration>

I put all the logs in ERROR level so I will be able to just verify that the configuration files are being read, but when printing a single log for EVERY level, the console keeps printing the default level (INFO, WARN and ERROR)

I assume that the no configuration file is being read/detected.

Which configuration file should I be using, and where should I place it for it to identify it? Or maybe I'm confused and we are not able to configure logs with this configuration and I should be looking into another implementation of lombok? I'm kind of lost in here.

White_King
  • 748
  • 7
  • 21

2 Answers2

0

It's enough to put just a single logback.xml to your classpath (e.g. /src/main/resources). It's a doc page about how Logback lookups the configuration file. But for some libraries, you have to use bridges to redirect "old" loggers to Logback.

Related questions: common-logging, JUL

Andrei Kovrov
  • 2,087
  • 1
  • 18
  • 28
  • Like I explain in the question, I already have the logback.xml that your first resource mentions BOTH in resources in src. I'm not sure if I understood what a bridge is, but I'm sure I didn't understand how to configure it, I think I need to substitute a JAR in the project so another (maybe logback) will take control over the configuration, but I have no idea how to do that from the document. Also I'm not using logback for any specific reason and if changing logback dependency can fix things I'm open to it. in the related questions they just mention bridges as well – White_King Dec 08 '21 at 14:21
  • In the second resource (JUL) The logger that Lombok uses is org.slf4j.Logger not JUL directly I'm not sure if this applies to what I'm working on, but I tried adding the `jul-to-slf4j` dependency and added the configuration as the resource requested and it won't work (it will not change the level of the logs) – White_King Dec 08 '21 at 14:28
  • 1
    Post example your code using logging/probably other dependencies you use/log output example. The information is provided by you is not sufficient to answer the question. – Andrei Kovrov Dec 08 '21 at 15:06
  • Following your suggestion I made a sample project [https://github.com/white-sdev/lombok-logging] with the configurations I'm listing so you can take a look at it. – White_King Dec 08 '21 at 20:56
0

This is not a direct answer but it is a solution to the main question. Instead of using logback-classic dependency we can switch to a log4j-slf4j-impl implementation of slf4j and use the log4j2.properties file to configure levels and Format/Layout Pattern as shown in the sample repository to obtain this kind of logs:

enter image description here

White_King
  • 748
  • 7
  • 21