cannot get logback TRACE logs output for my java spring application

103 Views Asked by At

I am trying to use logback for TRACE logging for a Spring application. However, with the configuration I have, I only get up to DEBUG logs output to the console.

Any ideas if there is some configuration that will help me get TRACE as well?
I have read several tutorials and haven't found much. This is what I have so far for configuration:

using java 19

logback.xml:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
    </appender>
    
    <root level="trace">
        <appender-ref ref="STDOUT" />
    </root>
    
    <logger name="org.springframework.security" level="trace">
        <appender-ref ref="STDOUT" />
    </logger>

</configuration>

relevant pom.xml:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.5.0</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>2.1.0-alpha1</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.5.0</version>
</dependency>

2

There are 2 best solutions below

11
Per Huss On BEST ANSWER

I'm getting spring security trace logging with your logback.xml file. So my take is that either spring security is not doing any trace logging in your scenario, or your logback.xml is not in effect. The latter can probably be eliminated if you get debug logging for spring security on your console...

2
Marc Le Bihan On

Maybe I show you a logback test config I use for logging?
It is working for me. I hope it can give you ideas to find where your issue is coming from, by comparing with yours?

logback-test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <property name="LOG_FILE" value="/tmp/ecoEmploi-test-sparkDatasetEntreprise.log"/>
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>

    <logger name="fr" level="DEBUG" />

    <logger name="org.eclipse.jetty.server.handler.ContextHandler" level="WARN" />
    <logger name="org.sparkproject.jetty.server.handler.ContextHandler" level="WARN" />

    <logger name="org.apache.hadoop.io.compress.CodecPool" level="WARN" />
    <logger name="org.apache.spark.util.collection.unsafe.sort.UnsafeExternalSorter" level="WARN" />
    <logger name="org.apache.parquet.hadoop.ParquetOutputFormat" level="WARN" />

    <logger name="org.apache.spark.sql.execution.datasources.InMemoryFileIndex" level="WARN" />
    <logger name="org.apache.spark.sql.execution.datasources.FileSourceStrategy" level="WARN" />
    <logger name="org.apache.spark.sql.execution.datasources.DataSourceStrategy" level="WARN" />
    <logger name="org.apache.spark.sql.execution.FileSourceScanExec" level="WARN" />

    <logger name="org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter" level="WARN" />
    <logger name="org.apache.spark.sql.execution.datasources.SQLHadoopMapReduceCommitProtocol" level="WARN" />
    <logger name="org.apache.parquet.hadoop.codec.CodecConfig" level="WARN" />

    <logger name="org.apache.spark.scheduler.DAGScheduler" level="WARN" />
    <logger name="org.apache.spark.scheduler.TaskSetManager" level="WARN" />
    <logger name="org.apache.spark.scheduler.TaskSchedulerImpl" level="WARN" />

    <logger name="org.apache.spark.executor.Executor" level="WARN" />
    <logger name="org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator" level="WARN" />

    <logger name="org.apache.spark.storage.ShuffleBlockFetcherIterator" level="WARN" />
    <logger name="org.apache.spark.storage.BlockManager" level="WARN" />
    <logger name="org.apache.spark.storage.BlockManagerInfo" level="WARN" />
    <logger name="org.apache.spark.storage.MemoryStore" level="WARN" />
    <logger name="org.apache.spark.storage.memory.MemoryStore" level="WARN" />
</configuration>