• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4j date/time

 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i simply log the date and the time in each line?
I found several examples around, but none of them works


Regards
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have the %d in your *.layout.ConversionPattern property - it should write a date and time in each line.

The %d can you then setup to a custom format e.g. %d{HH:mm:ss} will only write the time in 24 hour format.
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my log4j.properties file:

<![CDATA[

log4j.debug=true
# Global logging configuration
log4j.rootLogger=INFO, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.out
#log4j.appender.stdout.Threshold=DEBUG


log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss} %5p [%t] - %m%n
#log4j.appender.CON.layout.ConversionPattern=%d %p %C - %m%n


# SqlMap logging configuration...
log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
#log4j.logger.com.ibatis.common.jdbc.logging.PreparedStatementLogProxy=DEBUG
#log4j.logger.com.ibatis.common.jdbc.logging.ConnectionLogProxy=DEBUG
#log4j.logger.com.ibatis.common.jdbc.logging.ResultSetLogProxy=DEBUG
#log4j.logger.com.ibatis.common.util.StopWatch=DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
#log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientImpl=DEBUG
#log4j.logger.com.ibatis.sqlmap.engine.cache.CacheModel=DEBUG
#log4j.logger.com.ibatis.sqlmap.engine.builder.xml.SqlMapParser=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
#log4j.logger.java.sql=DEBUG
]]>

logger.info("FirstAction->execute"); // <---This is how i log events in code


And the example log:

INFO [http-8080-Processor24] - FirstAction->execute
DEBUG [http-8080-Processor24] - {conn-100003} Connection


I don't see the Date?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently using this setup


and the output is like this:
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to restart Tomcat before the changes in log4j.properties take effect -that was the problem.
It's working now.

Thanks for your help!


Regards
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic