When I'm tapping on the log button corresponding to my application of spring boot admin dashboard I'm getting Error while reading logfile: - error. Does somebody faced this already?
I'm using log4j with such configuration:
<?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="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE}] [%-5p] [%c{1}] [%t] [%m]%n"/>
</layout>
</appender>
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="maxFileSize" value="10KB" />
<param name="maxBackupIndex" value="5" />
<param name="file" value="service-rest.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE}] [%-5p] [%c{1}] [%t] [%m]%n"/>
</layout>
</appender>
<root>
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="file" />
</root>
</log4j:configuration>
My application.yml file has such logging section:
logging:
file: "service-rest.log"
level:
org:
springframework:
boot:
autoconfigure:
logging: DEBUG
Also I could get that logfile from app directly http://url/actuator/logfile
The problem was the slightly wrong format of logs that has been pushed to service-rest.log file. The right one appender for file is
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="maxFileSize" value="10MB" />
<param name="maxBackupIndex" value="5" />
<param name="file" value="tvpp-rest.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] [%t] [%m]%n"/>
</layout>
</appender>
Without that brackets around time and log level.
Related
Okay, this is driving me nuts. I have an app that uses log4j 1.2.16, my configuration file is properly picked up and log4j writes to the file that I want, BUT it only logs error level.
Code:
import org.apache.log4j.Logger;
- (... code omitted)
private static final Logger LOGGER = Logger.getLogger(PostLoginController.class);
LOGGER.debug("TOTO debug");
LOGGER.info("TOTO Info");
LOGGER.warn("TOTO warn");
LOGGER.error("TOTO error");
XML:
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/jboss/jboss-eap-6.4/standalone/log/myLogFile.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p [%t:%c] : %m%n"/>
</layout>
</appender>
<!-- Root Logger -->
<root>
<priority value ="debug" />
<appender-ref ref="fileAppender"/>
</root>
When my app runs myLogFile is created and I can see the error log in it, but not the other ones:
2019-06-06 19:37:31 ERROR [http-/0.0.0.0:8080-2:my.classpath.PostLoginController] : TOTO error
Any idea what's wrong here?
You have to use like this for logging debug to error.
<log4j:configuration debug="false">
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] - %m%n" />
</layout>
</appender>
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<param name="file" value="/jboss/jboss-eap-6.4/standalone/log/myLogFile.log"/>
<param name="append" value="false" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] - %m%n" />
</layout>
</appender>
<root>
<priority value="info" />
<appender-ref ref="default.console" />
<appender-ref ref="default.file" />
</root>
</log4j:configuration>
Okay, figured it out. I had to add
<category name="my.classpath">
<priority value="all" />
<appender-ref ref="fileAppender" />
</category>
because somehow the rootLogger level can't be altered.
Problem:
We got 2 logs printed in the file like this:
Analysis
1)These 2 logs are printed one after the other in the code and here too but the time difference is 7 minutes which is huge.
2)This has been observed when there is only one War file as well as multiple wars in the Tomcat.
Below is the log4j configuration file to analyse the issue clearly:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
</layout>
</appender>
<appender name="callback" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="file" value="${catalina.base}/logs/subs_engine.log" />
<param name="append" value="true" />
<param name="encoding" value="UTF-8" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern"
value="${catalina.base}/logs/%d{yyyy-MM-dd_HH}_subs_engine.gz" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="info" />
<appender-ref ref="callback" />
</root>
</log4j:configuration>
Can anyone guide me how to solve or debug this problem:
Is this the problem of log4j?
We are using log4j-1.2.17.jar
#Edit:
Logger.sysLog(LogValues.APP_DEBUG, Utility.class.getName(),"Inside loadHttpReqToBean.");
Logger class Calling syslog method
I have below log4j configuration. when file reaches its max size , it is not rolling but when I restart server then rolling is working.
Please let me know what I am wrong in my configuration.
<appender name="ALog" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="true" />
<param name="maxFileSize" value="10KB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="logs/Log.txt" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value ="debug"/>
<appender-ref ref="ALog"/>
</root>
Thanks.
You have to do :
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<appender-ref ref="file"/>
I have a java web application that runs with tomcat7 and logs with log4j. I want to send my logs to rsyslog.
I have use the appeneder in my log4j.xml file.
<appender name="syslog" class="org.apache.log4j.net.SyslogAppender">
<param name="Facility" value="USER"/>
<param name="SyslogHost" value="localhost"/>
<param name="Threshold" value="WARN"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{MMM dd HH:mm:ss} MYAPP: %-5p %m%n"/>
</layout>
</appender>
But I still don't see the logs that I've implemented in my java application in rsyslog. I can see them in catalina.out but not on rsyslog.
Do I have to define new rules for rsyslog configuration?
Thanks in advance.
Updated log4j.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="System.out" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="Target" value="System.out" />
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">
<param name="SyslogHost" value="localhost"/>
<param name="Facility" value="LOCAL1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<!-- for package specific -->
<!-- <category name ="my.package" /> -->
<logger name ="Logger">
<level value ="debug" />
</logger>
<!-- root logger -->
<root>
<level value="info"/>
<appender-ref ref="SYSLOG"/>
</root>
I am using log4j for logging in my applicaion. I am trying to different level logs in different files but something going wrong. Any help regrading this issue will be highly appreciated.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_debug.log" />
<param name="Threshold" value="DEBUG" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="INFO" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_info.log" />
<param name="Threshold" value="INFO" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="ERROR" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_error.log" />
<param name="Threshold" value="ERROR" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="FATAL" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_repeat_delay.log" />
<param name="Threshold" value="FATAL" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<priority value ="error" />
<appender-ref ref="console"/>
<appender-ref ref="DEBUG"/>
<appender-ref ref="INFO"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="FATAL"/>
</root>
</log4j:configuration>
The standard behaviour for log4j appenders is that they log all messages at their threshold level or higher, i.e. an appender with threshold INFO will log INFO, WARN, ERROR and FATAL messages but not DEBUG. If you want to log only INFO messages but not WARN and above then you need to use a LevelMatchFilter.
You will also need to set your root logger priority to DEBUG, otherwise it will only send ERROR and FATAL messages to its appenders and your DEBUG and INFO files will be empty.