Spring 5 Reactor Netty log spam (too verbose) - spring

Is there a way to reduce console/log noise output in Spring 5 + Reactor + Netty. It's too verbose, especially full print out of a request:

This is what helped me:
pom.xml
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
src/main/resources/logback.xml
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.sssXXX, UTC} [%thread] %-5level %logger{15} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

Related

spring logback how to dinamically retrieve class and application name

I have the following logback-spring.xml configuration file:
<configuration scan="true">
<property name="LOG_PATH" value="/logs/application/"/>
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
<appender name="ALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<append>true</append>
<encoder>
<pattern>[%d{yyyy-MM-dd_HH:mm:ss.SSS}] %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 15 MegaBytes -->
<fileNamePattern>${catalina_home}/${LOG_PATH}/general-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>15MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>30</maxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="ALL" />
</root>
</configuration>
Now, I have my springboot application "Application" and within the class "MyClass" I call:
LoggerFactory.getLogger(MyClass.class);
I want to configure the log file name by changing the static name "general" in "Application-MyClass" (whatever is the application name). Any tips?

Logback TimeBasedRollingPolicy not saving the log with the desired name of the log file

I want to configure TimeBasedRollingPolicy in my spring boot project. I want the log file to be saved in a pattern 'mylog.%d{yyyy-MM-dd}.log'.
My logback-spring.xml file looks like the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p{${LOG_LEVEL_PATTERN}} %15.15t - %-80.80c{1.} %X{username} %X{ipaddress} : %msg%n</pattern>
</encoder>
</appender>
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/mylog.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p{${LOG_LEVEL_PATTERN}} %15.15t - %-80.80c{1.} %X{username} %X{ipaddress} : %msg%n</pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/mylog.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
</configuration>
But it's not working, the log file is created but it is not titled mylog but the default 'localhost_access_log.2022-05-16'. Can someone please help me with this?
Declare timestamp separately and refer it inside your fileNamePattern
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<timestamp key="timestamp" datePattern="yyyy-MM-dd"/>
// place all your appenders
<appender name="RollingFile"
.
.
.
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/mylog.${timestamp}.log</fileNamePattern>
</rollingPolicy>
</appender>
</configuration>

How to show sql Queries in console in springboot azure (Springboot + Azure Cosmos)

i am using SpringBoot with azurecosmos db
i want to see the query for below repository code.
findByFirstNameAndLastName(String firstName,String lastName);
For me adding following configuration to application.yaml worked.
logging:
config: classpath:logback-local-spring.xml
level:
com.azure.cosmos.implementation.SqlQuerySpecLogger: debug
You can try adding the below lines inside application.properties to get all the query generated in console
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
logging.level.org.hibernate.SQL = DEBUG
logging.level.org.hibernate.type = TRACE
logging.level.org.springframework.web = DEBUG
You can use also logback. Here is one example:
<configuration>
<include resource="/org/springframework/boot/logging/logback/base.xml"/>
<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="info">
<appender-ref ref="STDOUT"/>
</root>
<logger name="com.azure.cosmos" level="error"/>
<logger name="org.springframework" level="error"/>
<logger name="io.netty" level="error"/>
<logger name="com.azure.cosmos.implementation.SqlQuerySpecLogger" level="DEBUG"/>

How to log all requests and responses for Play Framework 2.5.x?

I want to log requests and responses for my application. I expect they should be present in access.log file. However, my access.log file is empty. I have enables access logging in configuration.
Here is my prod-logger.xml :
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.dir}/web/logs/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover with compression -->
<fileNamePattern>application-log-%d{yyyy-MM-dd}.gz</fileNamePattern>
<!-- keep 30 days worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss ZZZZ} [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>
<appender name="ACCESS_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.dir}/web/logs/access.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover with compression -->
<fileNamePattern>access-log-%d{yyyy-MM-dd}.gz</fileNamePattern>
<!-- keep 1 week worth of history -->
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss ZZZZ} %message%n</pattern>
<!-- this quadruples logging throughput -->
<immediateFlush>false</immediateFlush>
</encoder>
</appender>
<!-- additivity=false ensures access log data only goes to the access log -->
<logger name="access" level="INFO" additivity="false">
<appender-ref ref="ACCESS_FILE"/>
</logger>
<root level="INFO">
<appender-ref ref="FILE"/>
</root>

Logback-core UnknownHostException in catalina.out

I have problem with logback-core.
My project using apache-tomcat 7 webserver,
and this is a JSF project.
The server starts with this error message in the catalina.out,
but the instance and the webapps works well.
The logback-core-1.1.2.jar is in the $CATALINA_HOME/lib folder.
This is the appropriate path for this jar file?
What does this error mean? Any possible solutions?
Thank you!
The error message from catalina.out
-ERROR in ch.qos.logback.core.util.ContextUtil#17a1869 - Failed to get local hostname java.net.UnknownHostException
at java.net.UnknownHostException
at at ch.qos.logback.core.util.ContextUtil.getLocalAddressAsString(ContextUtil.java:59)
at at ch.qos.logback.core.util.ContextUtil.getLocalHostName(ContextUtil.java:41)
at at ch.qos.logback.core.util.ContextUtil.addHostNameAsProperty(ContextUtil.java:74)
at at ch.qos.logback.classic.joran.action.ConfigurationAction.begin(ConfigurationAction.java:57)
at at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:275)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:147)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:129)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
at at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
at at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
at at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
at at org.atmosphere.cpr.AtmosphereServlet.<clinit>(AtmosphereServlet.java:172)
at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at at java.lang.Class.newInstance(Class.java:374)
at at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:143)
at at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5198)
at at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5481)
at at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:634)
at at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1074)
at at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1858)
at at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at at java.lang.Thread.run(Thread.java:744)
logback.xml from $CATALINA_HOME/conf folder
<appender name="CONSOLE" class="org.apache.juli.logging.ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level {%thread} [%logger{20}] : %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE-CATALINA" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/catalina.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>%d{HH:mm:ss.SSS} %-5level {%thread} [%logger{40}] : %msg%n</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/catalina-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
<maxHistory>60<!-- days --></maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-LOCALHOST" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/localhost.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/localhost-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
<maxHistory>60<!-- days --></maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-MANAGER" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/manager.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/manager-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
<maxHistory>60<!-- days --></maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-HOST-MANAGER" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/host-manager.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/host-manager-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
<maxHistory>60<!-- days --></maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="PROJECT" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/project.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/host-manager-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
<maxHistory>60<!-- days --></maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<logger name="org.apache.catalina" level="INFO" additivity="false">
<appender-ref ref="FILE-CATALINA" />
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]" level="INFO" additivity="false">
<appender-ref ref="FILE-LOCALHOST" />
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]" level="INFO" additivity="false">
<appender-ref ref="FILE-MANAGER" />
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]" level="INFO" additivity="false">
<appender-ref ref="FILE-HOST-MANAGER" />
</logger>
<logger name="com.project" level="INFO" additivity="false">
<appender-ref ref="PROJECT" />
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
This happens because of library version mis match of logback-classic & logback-core, I have faced similar issue in tomcat 8, inside my project I have added logback-classic-1.1.7.jar and compile dependencies for the same is logback-core-1.1.7.jar which was not included but while deploying build tool used to download latest stable version of logback-core which was causing issue.
I fixed this by defining same version of logback-classic and logback-core.
I can't reproduce your error. :( Sorry
But what happens when you use this?
<configuration>
<contextName>test</contextName>
<appender
name="console"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%level %logger{55} - %msg%n</pattern>
</encoder>
</appender>
<logger
name="com.yourcompany"
level="debug" />
<root level="info">
<appender-ref ref="console" />
</root>
</configuration>
If this works, I would start systematically adding stanzas from your logback to this one until you find the problem. Good luck!

Resources