I have the following issue:
I have an enviroment with apache tomcat 7.0.72 and I have three logs, cmfront, cmback and catalina.out.
The configuration of both (cmfront and cmback) is the same, cmfront:
# Root logger option
log4j.rootLogger=OFF
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/CmFront.log
log4j.appender.file.MaxFileSize=20MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.CmFront=INFO,file,stdout
and cmback:
# Root logger option
log4j.rootLogger=OFF
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/CmBack.log
log4j.appender.file.MaxFileSize=20MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.CmBack=INFO,file,stdout
log4j.logger.o=OFF
Nevertheless, when I deploy cmfront war, I deploy without any problem, but when I try whit cmback, my file does not write anyhting and also has the following logging lines:
16:08:28.768 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
16:08:28.768 [localhost-startStop-1] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
And a lot of this kind of lines, my question is why in one war the logging properties works and does not print o.s.... debug lines, and by another hand the logs does not is written and also print a lot of debug lines if the configuration is the same?
the properties are not application specific but spring related properties
if you have configured any spring bean related to mbean or any other , i think you can ignore those as long as the application is not affecting.
As far as the logging,
try the below
log4j.rootLogger=INFO,file,stdout
y r u setting root logger off, as you are not having any specific logger defined like com.****.com all your logs should go through the root logger.
For logs to work you should enable the root logger.
This is my guess might not be exact answer
Related
Tried to find an answers in other questions but nothing helped.
While running my program the log4j sent at the beginning:
log4j:WARN No such property [conversationPattern] in org.apache.log4j.PatternLayout.
This is my log4j.properties file:
# Root logger option
log4j.rootLogger = warn, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\Users\\xxxcx\\Desktop\\automationTest.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversationPattern=%d{yyyy/MM/dd HH:mm:ss} %-5p
%c{1}:%L - %m%n
I don't understand how to solve it because i can find whats the problem with my conversationPattern property.
Any help would be great!
For log4j 1 it is ConversionPattern and not ConversationPattern. That is simply change your pattern config to this:
log4j.appender.file.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %-5p
I think the property for log4j2 is simply called pattern and not ConversationPattern:
appender.file.layout.pattern=%d{yyyy/MM/dd HH:mm:ss} %-5p
I am using log4j in my java application. My log4j property file is as follows
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=file_path
log4j.appender.file.MaxFileSize=500MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Problem I am facing is maxfilesize is defined as 500 MB, so my understanding is that after 500 MB a new log file should be generated but in my case new file is getting generated only after server restart. If I don't resstart my server, logs get accumulated in the same file even after 500 MB limit. How to resolve it? Is it the normal behaviour of log4j or there is something wrong with my configuration?
I have a log4j properties file defined like so:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.com.github.user=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=target/cucumber-parser.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Based on my understanding, INFO level logging should be routed to stdout (console) and DEBUG should be only written to file. However I get both, INFO and DEBUG level in console. What am I doing wrong?
I managed to solve my problem by applying the below line to log4j.appender.stdout:
log4j.appender.stdout.Threshold=INFO
With this line added to the original configuration that I posted in my original question, only the INFO level logs will be printed to the console and DEBUG will be rerouted to a file as desired.
Because INFO level covers DEBUG level. So that you see both.
See more Logging Levels
If you check log4j doc or this tutorial you can see more information about levels, but basically: ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF
So log shows the selected level and all the greaters.
add log4j.additivity.com.github.user=false.
As in your config, level of com.github.user is being set to debug. And besides "file", it will also be additive to root logger, so you can see debug log of com.github.user in the console.
In fact, if you write the config this way, splitting loggers and appenders, you can understand better.
log4j.rootLogger=INFO, stdout
log4j.logger.com.github.user=DEBUG, file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=target/cucumber-parser.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
For loggers, you specified com.github.user to be debug, and all others info with rootlogger setting.
Then com.github.user will be printed to file, and all logs will be printed to console . And if you set the additivity, com.github.user will be removed from rootlogger, so there will only be other logs in console.
I am facing problem in Log4j,like in my Maven Rest API project i have log4j.propeties file like below.
# Root logger option
log4j.rootCategory= TRACE, stdout, file
# Each package has different appender name
log4j.logger.club.exbrain.hht.service.management=TRACE, club.exbrain.hht.service.management
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#Redirect to Tomcat logs folder
log4j.appender.file.File=${catalina.home}/logs/logging.log
log4j.appender.file.MaxFileSize=25MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Issue is When i am running tomcat server from Eclispe i am getting my all logs in tomcat logs folder but when i export war file and deployed it to server i am getting warning message like below
log4j:WARN No appenders could be found for logger (org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap).
log4j:WARN Please initialize the log4j system properly.
Please tell where i can put this Log4j file or is there any possibilities is there to get the log
Everything works just as fine. But showing this error.
My log4j.properties file like :
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.myAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=D:\\log4j-application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Thanks in advance. Just tell me how to do it. I just want log file on daily rolling .
DailyRollingFileAppender doesn't support MaxFileSize, RollingFileAppender does.
DailyRollingFileAppender is for rolling files based on the date and time of the log entry, so if you want to use it you should remove the MaxFileSize property.
I changed the code to
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
from
log4j.appender.FILE=org.apache.log4j.FileAppender
and it worked fine in log4j.properties file