Showing posts with label log4j. Show all posts
Showing posts with label log4j. Show all posts

Tuesday, April 29, 2014

concurrent log4j

Log4j is the logging implementation on most JavaEE app-servers out there, so that's a good advert for its concurrency abilities.
Having said that, I have seen Log4j 1.2 deadlock under high load conditions. A bit of investigation highlighted some scarily bad synchronization in the source code. Apparently, this was fixed in Log4j 1.3, although development on this has slowed or stopped altogether - I get the feeling much of the source was unsalvageable.
However, if you're free to choose, then you should consider Logback instead, the spiritual successor to Log4j. It's a ground-up redesign, and is probably a better option for you.

Production settings file for log4j?

Log4j 1.2 is vulnerable to deadlocks when toString() produces nested logging.
It also has performance-killing lock synchronization issues under heavy concurrent load. Like Category callAppenders synchronization causes java.lang.Thread.State: BLOCKED and Move org.apache.log4j.Category to reentrant read/write locks.
One caveat is to always constrain root category level to at least INFO or higher. This would prevent logging calls from acquiring unnecessary locks mentioned in the above issues. Just limiting appender threshold is not sufficient as it is taken into account later. See explanation with publish/subscribe analogy. Nested categories of interest can be individually given lower priorities if needed.

Friday, March 14, 2014

Double-logging in Hibernate

All I can think of:
  1. Check that your log4j config doesn't have multiple appenders defined at different levels? If you have your appender attached to the org.hibernate logger, and attached again to the org.hibernate.SQL logger, then you'll see this twice (unless you turn off additivity for the lower-level logger).
  2. You don't have the hibernate.show_sql property set on your SessionFactory? That doesn't enable logging to log4j (you do that through log4j config), it just dumps to the console. If your log4j is dumping to the console too you'll see it twice. However, that looks like a log4j format log line, not the console dumps done by hibernate, so that seems unlikely. Worth mentioning though.

Thursday, September 26, 2013

Enabling log4j logging in Hibernate

Hibernate 3 has integrated with slf4j logging which demands an additional step in getting Hibernate’s log4j logs. This is important because in debug mode, Hibernate logs the SQL query strings and the bind variable values. The steps to configure for capturing the log4j logs from Hibernate are below:
1. Place log4j, slf4j-api and slf4j-log4j jars in the classpath. I am using log4j-1.2.15.jar, slf4j-api-1.5.3.jar and slf4j-log4j12-1.5.3.jarfiles.
2. Now configure the log4j.properties (or XML) file and place it in your classpath. A sample properties file content is provided below. This will print all the logs on to the console. Configure a file appender if you want the logs to be writtwen to a file.
Sample log4j.properties:

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{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout
log4j.logger.org.hibernate=debug
log4j.logger.org.springframework=debug
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.SQL=trace
log4j.logger.org.hibernate.type= trace
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug

You are now good to go :) Happy logging !!

Thursday, January 31, 2013

log4j logging levels

The amount and type of information shown in the system and event logs is controlled by the log4j settings in the encrypted properties file managed through WBE Properties. Each message on the log is prefixed by the level of the message.
There are 5 levels of logging:
  • FATAL: shows messages at a FATAL level only
  • ERROR: Shows messages classified as ERROR and FATAL
  • WARNING: Shows messages classified as WARNING, ERROR, and FATAL
  • INFO: Shows messages classified as INFO, WARNING, ERROR, and FATAL
  • DEBUG: Shows messages classified as DEBUG, INFO, WARNING, ERROR, and FATAL