In Weblogic, using log4jdbc, I need to log queries (using org.jdbcdslog.StatementLogger) only in a specific file but not in console.
I tried to start Weblogic with this parameter
-Dlog4j.configuration=file:%LOG4JDBC_HOME%\log4j.xml
This is the content of log4.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG" />
<param name="File" value="./logs/aladin.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss} %-5p %-30.30c %m%n" />
</layout>
</appender>
<category name="org.jdbcdslog.StatementLogger">
<priority value="INFO" />
<appender-ref ref="fileAppender" />
</category>
<category name="org.jdbcdslog.ResultSetLogger">
<priority value="FATAL" />
<appender-ref ref="fileAppender" />
</category>
<root>
<level value="DEBUG" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
The problem is that in console I see either org.jdbcdslog.StatementLogger and org.jdbcdslog.ResultSetLogger logged at INFO level, in aladin.log (the only file I'd like to log in) I don't see any log of org.jdbcdslog.StatementLogger and org.jdbcdslog.ResultSetLogger classes.
Is there a way to log these two classes only in aladin.log and not in console?
Related
I have the following log4j configuration which works in that it produces two log files, one with the diverted SPRING logs and one where I am attempting to filter out the SPRING content so it is just log messages I have configured using the Logger:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/debug/debug.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C.%M() - %m%n" />
</layout>
</appender>
<appender name="SPRING" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/spring/spring.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C.%M() - %m%n" />
</layout>
</appender>
<logger name="org.springframework" additivity="false">
<level value="debug"/>
<appender-ref ref="SPRING"/>
</logger>
<logger name="org.hibernate" additivity="false">
<level value="debug"/>
<appender-ref ref="SPRING"/>
</logger>
<root>
<priority value="debug" />
<appender-ref ref="DEBUG"/>
<appender-ref ref="SPRING"/>
</root>
</log4j:configuration>
The problem I am having is that there are still some org.springframework.jdbc calls coming through to my debug log that I am expecting to get diverted to the SPRING log file.
2020-06-26 10:05:29,601 DEBUG [scheduling-1] org.springframework.jdbc.object.SqlCall.compileInternal() - Compiled stored procedure. Call string is [{call SQL(?, ?, ?, ?, ?, ?, ?)}]
2020-06-26 10:05:29,601 DEBUG [scheduling-1] org.springframework.jdbc.object.RdbmsOperation.compile() - RdbmsOperation with SQL [SQL] compiled
I tried adding another logger with no success:
<logger name="org.springframework.jdbc" additivity="false">
<level value="debug"/>
<appender-ref ref="SPRING"/>
</logger>
Any ideas why it isn't getting picked up by these loggers?
If you are using log4j2 you can use below format. Please have a look at log4j and log4j2 spring-examples and Spring-docs for references.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<!-- process ID -->
<Property name="PID">????</Property>
<!-- Log exception conversion -->
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
<!-- log level pattern -->
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
<!-- log date format -->
<Property name="LOG_DATEFORMAT_PATTERN">yyyy-MM-dd HH:mm:ss.SSS</Property>
<!-- Final console log pattern -->
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{${LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${LOG_LEVEL_PATTERN}} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
<!-- Final file log pattern -->
<Property name="FILE_LOG_PATTERN">%d{${LOG_DATEFORMAT_PATTERN}} ${LOG_LEVEL_PATTERN} ${sys:PID} --- [%t] %-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
</Properties>
<Appenders>
<!-- Console Appender -->
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" />
</Console>
<!-- File Appender -->
<RollingFile name="File" fileName="${sys:LOG_FILE}" filePattern="${sys:LOG_PATH}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>${sys:FILE_LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
</Appenders>
<!-- Different loggers -->
<Loggers>
<Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
<logger name="org.springframework.web" level="warn"/> <!-- pre-defined -->
<logger name="org.springframework.boot.actuate.endpoint.web" level="warn"/>
<logger name="org.springframework.jdbc.core" level="warn"/> <!-- pre-defined -->
<!-- Root configuration (Console/File) -->
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="File" />
</Root>
</Loggers>
</Configuration>
If it's still not working, Please check required logs are enabled or not. (to make sure they are not disabled from any configuration)
Note: If you are using spring-boot, Spring boot’s default logging uses Logback which is included as transitive dependency.
Can the level of a child logger be higher than the root logger's priority value?
My configuration is like below. Currently the package net.sf.log4jdbc still prints info level logs.
I didn't intend any line of unimportant net.sf.log4jdbc logs to be shown, though.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p| %m %C%n" />
</layout>
</appender>
<logger name="net.sf.log4jdbc">
<level value="warn" />
</logger>
<!-- Root Logger -->
<root>
<priority value="debug" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
What do I need to do to print all the logs of debug or higher level except for just some packages with higher log level set?
This is my configuration file of log4j, on Windows works fine but on centos only create the in /tmp/ControllerDebug.log file and nothing is written in it.
I have checked that it isn´t a problem of permissions.
My server is jboss.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/' >
<appender name="FileDebugAp" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${log.dir}/Controller_Debug.log" />
<param name="MaxFileSize" value="8000KB"/>
<!-- Keep one backup file -->
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p %c{1} - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG" />
<param name="levelMax" value="FATAL" />
</filter>
</appender>
<appender name="ConsoleErrorAp" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.err"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="ERROR" />
<param name="levelMax" value="FATAL" />
</filter>
</appender>
<logger name="com.optimi.xgeomanager" additivity="false">
<level value="ALL"/>
<appender-ref ref="FileDebugAp"/>
</logger>
<logger name="com.optimi.tps" additivity="false">
<level value="ALL"/>
<appender-ref ref="FileDebugAp"/>
</logger>
<root>
<priority value="DEBUG" />
<appender-ref ref="ConsoleInfoAp"/>
</root>
</log4j:configuration>
Well, I resolved this adding jboss-deployment-structure.xml file with this information:
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding
some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
</exclusions>
</deployment>
</jboss-deployment-structure>
My requirement is to log the messages to 3 separate log files.
I am using 3 appenders in a JBOSS server.
Three of them need to work in the way such as
1.RollingFileAppender, consoleAppender work for 'INFO' and 'ERROR' modes.
2.DailyRollingFileAppender for 'ERROR' mode and for a specific category only.
I have tried lots of combinations like changing the priority value and the categories, but I have so far found no way in which all the three work simulatneously. Either fileAppender and ConsoleAppender work(logging both ERRROR and INFO) and the DailyRollingFileAppender does not or DailyRollingFileAppender does but the other two log only ERRORS not INFO.
Please tell me a way so that the three of them work.
Below mentioned is the log4j.xml I am using.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- file appender -->
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="C:/logs/mdmWSServer.log" />
<param name="MaxBackupIndex" value="5" />
<param name="MaxFileSize" value="5MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] [%t] [%-5p][ %c:] %m%n"/>
</layout>
</appender>
<appender name="dailyFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="C:/logs/dailyApp.log"/>
<param name="MaxBackupIndex" value="5" />
<param name="MaxFileSize" value="5MB" />
<param name="DatePattern" value="'.'yyyy-MM-dd-HH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] [%t] [%-5p][%c:] %m%n"/>
</layout>
</appender>
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ISO8601}] [%t] %m%n"/>
</layout>
</appender>
<category name="com">
<priority value="INFO"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="consoleAppender"/>
</category>
<category name="com.gsk">
<priority value="ERROR"/>
<appender-ref ref="dailyFileAppender"/>
</category>
<category name="org.apache">
<priority value="INFO"/>
<appender-ref ref="fileAppender"/>
</category>
<root>
<priority value="DEBUG"/>
<appender-ref ref="fileAppender"/>
<appender-ref ref="consoleAppender"/>
</root>
</log4j:configuration>
You can restrict an appender to only log a certain level by using filter class specifying which level you would want to log . See the sample code below
<appender name="TRACE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%t] %-5p %c - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG" />
<param name="levelMax" value="DEBUG" />
</filter>
</appender>
I am not sure how to log bean validation messages when using log4j and hibernate validator.
I tried using a "org.hibernate.validator" category in log4j resulting in a runtime exception...
I also tried using "javax.validation" category in log4j; however nothing gets logged.
Can anyone please help?
Regards,
Edit: Here is my log4j config:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d: %5p (%F:%L) %m%n"/>
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="output.log"/>
<param name="MaxFileSize" value="2000KB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c - %m%n"/>
</layout>
</appender>
<category name="org.apache.tapestry5">
<priority value="INFO"/>
</category>
<category name="com.bignibou">
<priority value="DEBUG"/>
</category>
<category name="org.hibernate.validator.engine.ValidatorImpl">
<priority value="TRACE"/>
</category>
<root>
<priority value="WARN"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
Do you have the log4j binding for sl4f on your classpath? You might also have a look at the log4j.properties file used for tests in Hibernate Validator.