How do you get log4j to roll files based on date and size?

Looks like you want a mix of the http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html and the http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html. You’ll have to code by yourself. The good news is: you’ll just have “merge” those classes functionality, no “low level” new code required.

Filtering out log4j messages from third-party frameworks?

In my log4j.properties file I set the root logger logging level to ERROR. Then for packages I specifically want to log, like my application code, I set the logging level to INFO or DEBUG. log4j.rootLogger=ERROR, stdout log4j.logger.com.initech.tps=DEBUG log4j.logger.org.hibernate.SQL=INFO I see co-workers who set root logging low and then end up listing everything they don’t want … Read more

Log4J2 property substitution – default

Default Property map Looking at http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution you can specify a default property map in the configuration file. That takes this form: <Configuration status=”debug”> <Properties> <Property name=”oauthLoginLogPath”>default/location/of/oauth2.log</Property> </Properties> … <Appenders> <Appender type=”File” name=”File” fileName=”${sys:oauthLoginLogPath}”> …. </Configuration Then, if you start your app with system property -DoauthLoginLogPath=/path/oauth2.log, the File appender fileName value will first be looked up … Read more

How to configure log4j to only keep log files for the last seven days?

I assume you’re using RollingFileAppender? In which case, it has a property called MaxBackupIndex which you can set to limit the number of files. For example: log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=example.log log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=7 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c – %m%n

Java Log Viewer [closed]

Just wanted to say that I’ve finally found a tool that I can get along with just fine… It’s called LogExpert (see http://www.log-expert.de/) and is free. Besides the usual tail function, it also has a filter and a search function – two crucial things that are missing from BareTail. And if you happen to want … Read more

Parse a log4j log file

I didn’t realize that Log4J ships with an XML appender. Solution was: specify an XML appender in the logging configuration file, include that output XML file as an entity into a well formed XML file, then parse the XML using your favorite technique. The other methods had the following limitations: Apache Chainsaw – not automated … Read more

Enable Hibernate logging

Hibernate logging has to be also enabled in hibernate configuration. Add lines hibernate.show_sql=true hibernate.format_sql=true either to server\default\deployers\ejb3.deployer\META-INF\jpa-deployers-jboss-beans.xml or to application’s persistence.xml in <persistence-unit><properties> tag. Anyway hibernate logging won’t include (in useful form) info on actual prepared statements’ parameters. There is an alternative way of using log4jdbc for any kind of sql logging. The above answer … Read more