I'm trying to capture logging messages, stdout, and stderr for my webapp, which is running under Tomcat 7.
I have a log4j.properties file in my war file, at WEB-IN/classes/log4j.properties, pretty much copied from the log4j docs, except with a filename "myapp.log":
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.File=${catalina.home}/logs/myapp.log
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
WEB-INF/lib includes log4j-1.2.14.jar and commons-logging-1.0.4.
I'm expecting to see myapp.log appear in Tomcat's log directory, but it's not. Please explain to me what I'm doing wrong.
You're using a ConsoleAppender where you should be using a file appender:
log4j.appender.A1=org.apache.log4j.RollingFileAppender
Related
I want to see the INFO level logs that Ignite prints during its running(so that it will help me on what Ignite is doing). I am using the following log4j.properties to make Ignite print INFO level logs,but the logs are not printed out.
Are there special configuration to make Ignite logs printed out?
Thanks.
log4j.rootCategory=INFO, stdout , R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %d - [TS] %c %M(%L) - %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=c:/ioc.ignite.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %d - [TS] %c %M(%L) - %m%n
log4j.logger.org.apache.ignite=INFO
log4j.logger.org.springframework=WARN
Please follow below steps:
e.g. if you are using log4j for logging
configure ignite/config/ignite-log4j.xml in gridLogger of IgniteConfiguration
e.g.
.........
uncomment "CONSOLE" appender in ignite/config/ignite-log4j.xml
copy ignite/libs/optional/ignite-log4j/log4j.jar and ignite/libs/optional/ignite-log4j/ignite-log4j.jar in ignite/libs/ folder
you can also set IGNITE_LOG_HOME environment variable to redirect the logs to any file
You should use <CLASSPATH>/config/ignite-log4j.xml file instead of log4j.properties.
Our view layer are made from JSF 2.1.4,Icefaces 3.3.When we are starting our application we are able to see all the logs in eclipse console is there any way to log all the icefaces logs into a file .
# configure the ice-faces logging
log4j.appender=org.apache.log4j.RollingFileAppender
log4j.appender.File=D:/icefaces.log
log4j.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n
log4j.appender.com.icesoft.faces.application.D2DViewHandler=FINEST
log4j.appender.com.sun.faces.config.ConfigureListener=FINEST
log4j.appender.org.icepush=FINEST
log4j.appender.org.icepush.application.PushRenderer=FINEST
log4j.appender.org.icepush.application.PortableRenderer=FINEST
log4j.appender.org.icefaces=FINEST
I have added the above code in my log4j.properties file, but it is not working I got from here here it is doing console appender, but I want FileAppender. Without specifying anything how it will decide what to log e.g I have configured other logs and it is logging, in the log4j.properties I have mentioned like
log4j.appender.defalut=org.apache.log4j.RollingFileAppender
log4j.appender.defalut.File=D:/xyz.log
log4j.appender.defalut.MaxFileSize=20MB
log4j.appender.defalut.MaxBackupIndex=5
log4j.appender.defalut.layout=org.apache.log4j.PatternLayout
log4j.appender.defalut.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n
i am new to log4j and i have the following log4j.properties file in my java application
i am working on this in websphere 6.1
log4j.properties file
log4j.rootLogger=info, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.package_name=debug
However this is working if i am using only one project as part of my application.If there are multiple projects and i want to use logging facility,logger.isDebugEnabled() always return false.. can anybody suggest a solution for this?
Thanks in advance
Websphere use a classloader for default for each EAR. If you have several Web modules or EJB modules and several files for log4j, only one is loaded by the classloader.
See A Powerful, Easy-to-Use Logging System for configure log4j with several projects in a EAR.
# Set root logger level to INFO and appender to STDOUT.
log4j.rootLogger=INFO, STDOUT
#------------------------------------STDOUT-----------------------------------#
# STDOUT is set to be a ConsoleAppender.
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
# STDOUT uses PatternLayout.
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %-5p (%c.java:%L).%M - %m%n
log4j.appender.STDOUT.Encoding=UTF-8
#-----------------------------------------------------------------------------#
# Specify the logging level for loggers from other libraries
log4j.logger.org.apache.commons.beanutils.BeanUtils=DEBUG
log4j.logger.org.apache.struts.action=DEBUG
log4j.logger.org.apache.struts.tiles=DEBUG
log4j.logger.org.apache.struts.util.ModuleUtils=DEBUG
log4j.logger.org.apache.struts.util.RequestUtils=DEBUG
log4j.logger.org.apache.struts.util.PropertyMessageResources=ERROR
log4j.logger.com.ibm._jsp=DEBUG
May you are missing the log4j.logger. prefix for each particular package.
See more of log4j in http://logging.apache.org/log4j/1.2/manual.html
I have a problem where log4j is not logging to one of my files and i'm not sure why. I have some code that runs scripts, the scripts can add logging which is logged to a file using log4j, I am trying to create an appender that only logs for a particular script.
log4j.logger.com.my.class=INFO, JS_LOG
log4j.appender.JS_LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.JS_LOG.Encoding=UTF-8
log4j.appender.JS_LOG.File=${log.outputdir}/js_service.log
log4j.appender.JS_LOG.MaxFileSize=2MB
log4j.appender.JS_LOG.MaxBackupIndex=10
log4j.appender.JS_LOG.Append=true
log4j.appender.JS_LOG=org.apache.log4j.RollingFileAppender
log4j.appender.JS_LOG.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
the above appender works and i get this in my log file
2012-04-18 11:25:52,043 [<MD> Inc Msg Dispatch-1 New] INFO com.my.class.file:/myfile - info
when the script logs something it logs to a logger of the form
com.my.class.file:/myfile this appears in the log using the above config in my log4j.properties file.
if I change the above to:
log4j.logger.com.my.class.file:/myfile=INFO, JS_LOG
log4j.appender.JS_LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.JS_LOG.Encoding=UTF-8
log4j.appender.JS_LOG.File=${log.outputdir}/js_service.log
log4j.appender.JS_LOG.MaxFileSize=2MB
log4j.appender.JS_LOG.MaxBackupIndex=10
log4j.appender.JS_LOG.Append=true
log4j.appender.JS_LOG=org.apache.log4j.RollingFileAppender
log4j.appender.JS_LOG.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
nothing is logged to the file. I would have thought this should work? I retrieve the file
I managed to solve this problem, its something to do with the file: in my log4j.properties I changed the appender to file_ then in my code I do some manipulation to the file url to make it match the appender.
i have the following log4j.properties file. what i want to do is log everything at the level INFO or above to the console. however, for anything that falls in the demo.* package, i want to log everything at the DEBUG level to a file. my log4j.properties below does not seem to work. what happens is that any DEBUG message from demo.* still gets output to the console. any idea what i am doing wrong?
how can i exclude demo.* from logging to the console?
log4j.rootLogger=INFO, C
log4j.logger.demo=DEBUG, R1
log4j.appender.C=org.apache.log4j.ConsoleAppender
log4j.appender.C.target=System.err
log4j.appender.C.layout=org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
log4j.appender.R1=org.apache.log4j.RollingFileAppender
log4j.appender.R1.File=output.log
log4j.appender.R1.MaxFileSize=5MB
log4j.appender.R1.MaxBackupIndex=5
log4j.appender.R1.layout=org.apache.log4j.PatternLayout
log4j.appender.R1.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
sorry, never mind. i solved it by setting the threshold of the console appender.
log4j.appender.C.threshold=INFO