How to turn off Soap Message CXF form STDOUT using logback - java

I'm working on web service using Apache cxf but in my console and catalina.out I had a lot of extra logs ,I'm using logback for logging.
I want to turn off logging soap message generated by org.apache.cxf.services,this my logback configuration :
<!-- Standard Output logger -->
<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>
<!-- File Appender -->
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/logs/output-log.log</file>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>1MB</maxFileSize>
</triggeringPolicy>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/output-log-%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} %-5p [%-10.10t]
%60.60c:%-3L%m%n
</pattern>
</encoder>
</appender>
<logger name="org.apache.cxf" level="ERROR" additivity="false">
<appender-ref ref="AUDITTRAIL" />
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<!-- appender-ref ref="SYSLOG" / -->
</logger>
<logger name="org.apache.cxf.interceptor" level="ERROR"
additivity="false" />
<logger name="org.apache.cxf.services" level="ERROR" additivity="false" />
<root level="INFO">
<appender-ref ref="AUDITTRAIL" />
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<!-- appender-ref ref="SYSLOG" / -->
</root>
Using this configuration I still get soap message in my console log and outlog file example :
mars 30, 2018 9:55:00 AM org.apache.cxf.services.WebServiceImplService.StartImplPort.WebService
INFOS: Inbound Message
----------------------------
ID: 5
Address: http://127.0.0.1:8089/glsid/ws/webService
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=utf-8
Headers: {Accept=[text/xml, text/html, image/gif, image/jpeg,
.......
Any help to fix this problem thanks in advance

Finally this solution work for me :
in the file : META-INF/cxf/org.apache.cxf.Logger
I added : org.apache.cxf.common.logging.Slf4jLogger
In the spring configuration : applicationContext :
I added :
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="loggingInInterceptor"/>
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="loggingOutInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
and to turn off soap logging in STDOUT in the logback.xml :
<!-- Apache CXF logger -->
<logger name="org.apache.cxf" level="INFO"/>
<logger name="org.apache.cxf.interceptor" additivity="false">
<!-- <appender-ref ref="STDOUT" /> -->
<appender-ref ref="FILE" />
</logger>
<root level="INFO">
<!-- <appender-ref ref="STDOUT" />-->
<appender-ref ref="FILE" />
</root>

Related

How to organize daily logging files in Logback

I am using Logback for logging. Now all logs are writing into one file, and it becomes very large. How to organize logging in such a way that a new file is created at the beginning of a new day?
I use such logback.xml
<configuration>
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %m%n" />
<property name="APP_LOG_ROOT" value="admin-logs"/>
<timestamp key="year" datePattern="yyyy" />
<timestamp key="month" datePattern="MM" />
<timestamp key="date" datePattern="dd" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5relative %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger level="INFO" name="my.name">
<appender-ref ref="STDOUT" />
</logger>
<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
all logs are writing into one file
The shown config is going to the STDOUT, not a file.
If you want to write to a daily file, use logrotate/cron process, or have logback do this itself.
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${LOG_DIR}/bim.%d{yyyy-MM-dd}.log</fileNamePattern>
...
</appender>
...
<logger level="INFO" name="my.name">
<appender-ref ref="file" />
</logger>
<root level="ERROR">
<appender-ref ref="file" />
</root>

How can i avoid the queries of my spring-boot with hibernate app will be written to console or file?

I have an app written in spring-boot.
I have the following files:
application.properties
spring.main.banner-mode=off
debug=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProfile name="dev">
<property name="LOGS" value="...." />
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</layout>
</appender>
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/signing-dev.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS}/archived/signing-dev-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<logger name="[mypackage]" level="error" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
<logger name="level.com.zaxxer" level="error" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
<logger name="org.hibernate" level="error" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
<logger name="org.thymeleaf" level="error" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
<logger name="org.springframework.security" level="error" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
</springProfile>
</configuration>
I want to avoid that my hibernate queries will be written to console or file, but they are written like this:
Hibernate: select employeead0_.id as id1_0_0_, employeead0_.type as type2_0_0_ from employee_admin employeead0_ where employeead0_.id=?
How can i configure logback to avoid this?
try add this to application.properties:
#show sql statement
logging.level.org.hibernate.SQL=error
#show sql values
logging.level.org.hibernate.type.descriptor.sql=error

Disable PDFBox logging with Springboot org.apache.commons.logging

I can't find a way to stop warnings from PDFBox I am using in a psring boot application. For example:
2019-10-01 16:53:51.021 WARN 24564 --- [nio-8443-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font : No Unicode mapping for CID+4 (4) in font Calibri-Bold
2019-10-01 16:53:51.022 WARN 24564 --- [nio-8443-exec-2] o.a.pdfbox.pdmodel.font.PDCIDFontType2 : Failed to find a character mapping for 4 in Calibri-Bold
2019-10-01 16:53:51.022 WARN 24564 --- [nio-8443-exec-2] o.a.pdfbox.pdmodel.font.PDCIDFontType2 : Failed to find a character mapping for 4 in Calibri-Bold
I have tried:
In Application file:
static {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("org.apache.pdfbox").setLevel(java.util.logging.Level.OFF);
String[] loggers = {
"org.apache.pdfbox.util.PDFStreamEngine",
"org.apache.pdfbox.pdmodel.font.PDSimpleFont",
"org.apache.pdfbox.pdmodel.font.PDFont",
"org.apache.pdfbox.pdmodel.font.FontManager",
"org.apache.pdfbox.pdfparser.PDFObjectStreamParser",
"o.a.pdfbox.pdmodel.font.PDCIDFontType2",
"org.apache.pdfbox.pdmodel.font.PDCIDFontType2",
"o.a.pdfbox.pdmodel.font.PDType0Font",
"org.apache.pdfbox.pdmodel.font.PDType0Font",
"org.apache.pdfbox.pdmodel.font.PDType1Font"
};
for (String logger: loggers) {
org.apache.log4j.Logger logpdfengine = org.apache.log4j.Logger
.getLogger(logger);
logpdfengine.setLevel(org.apache.log4j.Level.OFF);
}
}
As parameter when running jar:
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
-Dorg.slf4j.simpleLogger.defaultLogLevel=off
Within the PDFBox code, the log is set up using:
(import org.apache.commons.logging.LogFactory;)
private static final Log LOG = LogFactory.getLog(PDCIDFontType0.class);
LOG.warn("Found PFB but expected embedded CFF font " + fd.getFontName());
I've spent a long time trying a lot of things and trolled through the answers for similar questions in SO but not got anywhere.
This is the configuration file I ended up using. I didn't include any logging releated dependencies or add any exclusions to pdfbox dependency, just added this file to the folder containing the application.properties file.
Filename is logback-spring.xml
The flooding logger was copied from how to change log levels of 3rd party library in java
<property name="LOGS" value="./logs" />
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<!-- LOG "com.baeldung*" at TRACE level -->
<logger name="org.apache" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
<logger name="flooding logger" level="ERROR" additivity="false">
<appender-ref ref="Console"/>
Here's what I have been using in the "old" log4j log4j.properties file (you should migrate to log4j2):
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.pdfbox.pdmodel.font.PDCIDFontType2=FATAL
In the "new" log4j2.xml I have this (the appenders are named STDOUT and A1):
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://logging.apache.org/log4j/2.x/manual/configuration.html
https://logging.apache.org/log4j/2.x/manual/appenders.html
-->
<Configuration>
<Appenders>
....
....
</Appenders>
<Loggers>
<Logger name="org.springframework" level="warn" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="A1"/>
</Logger>
<Logger name="org.apache.pdfbox.pdmodel.font.PDCIDFontType2" level="fatal" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="A1"/>
</Logger>
<Root level="info">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="A1"/>
</Root>
</Loggers>
</Configuration>
I think this also should work for log4j2. I use this simple way of disabling logs from specific libraries in SpringBoot applications. You need just add it into the log4j2.xml file.
<Loggers>
<Root>
****** here is some AppenderRef *******
</Root>
<Logger name="o.a.pdfbox" level="off"/>
or
<Logger name="org.apache.pdfbox" level="off"/>
</Loggers>

logback - Debug Level does not work

I have a JAVA EE application that uses logback (intended as a successor to the popular log4j project)
Here the logback.xml file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- trace, debug, info, warn, error, fatal -->
<timestamp key="myTimestamp" datePattern="yyyy-MM-dd'_'HH-mm-ss.SSS"/>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<!-- To enable JMX Management -->
<jmxConfigurator/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm"} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>telefonica.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>telefonica.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>5MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm"} [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.telefonicaā€¯ level="debug" />
<logger name="org.springframework" level="debug" />
<logger name="org.springframework.web" level="debug" />
<logger name="org.springframework.security" level="debug" />
<root level="debug">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
In 1 of the class inside the package com.telefonica I have this code
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public static final Logger log = LoggerFactory.getLogger(TS.class);
log.debug ("logging to WS " + WS_VERSION);
and I don't see anything in the console, but I see it when I put log.info ("logging to WS " + WS_VERSION);
Try adding appender to your logger like below
<logger name="org.springframework" additivity="false">
<level value="DEBUG" />
<appender-ref ref="STDOUT" />
</logger>
PLease refer this question and solution
Spring : Logging not working with log4j or logback
Change your logger level to level="DEBUG" from INFO
<logger name="org.springframework" level="DEBUG"/>

Logback can't write in console

I am using Logback in my spring boot application.
The problem is logback do not print my logger messages in 'eclipse' console for my both 2 packages dao and web.
The log file is written without any problem , and print my logger messages.
I am the root so probably I should see my logger messages in my console.
logger.info("Page X INFO");
logger.debug(" Page X Debug ");
Here is my logback.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Send debug messages to System.out -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<!-- Send debug messages to a file at "C:/logs/Log.log" -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>C:/logs/Log.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>C:/logs/Log.%i.log.zip</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>10</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="package.web" level="INFO" >
<appender-ref ref="FILE" />
</logger>
<logger name="package.dao" level="DEBUG" >
<appender-ref ref="FILE" />
</logger>
<!-- By default, the level of the root level is set to DEBUG -->
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
<logger name="package.web" level="INFO" >
<appender-ref ref="FILE" />
</logger>
You need to add the console appender.
<logger name="package.web" level="INFO" >
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</logger>
UPDATE: I just reread the logback config doku. Actually, those two should inherit both appenders from root. So, what you can try is to not specify any appender-ref on those and see what happens. If no output is written to the file then, neither - then there is something pretty strange. I'd expect that behavior if the additivity flag was set to false. But the default is appender accumulation.

Categories