aspose file tools*
The moose likes Tomcat and the fly likes Log4j date/time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Log4j date/time" Watch "Log4j date/time" New topic
Author

Log4j date/time

Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
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

Joined: Oct 12, 2001
Posts: 1179

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.


Regards, Rene Larsen
Dropbox Invite
Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
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

Joined: Oct 12, 2001
Posts: 1179

I am currently using this setup


and the output is like this:
Imre Tokai
Ranch Hand

Joined: Jun 04, 2008
Posts: 130
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4j date/time
 
Similar Threads
Date problem on server
getting last row
2 dates per post?
How to display one image per day from an array?
Date question