log4j with timestamp per log entry
Asked 07 September, 2021
Viewed 600 times
  • 56
Votes

this is my log output

INFO main digestemails - process inbox
INFO main digestemails - checking for emails in c:developmentDCMailemailKN-Source
INFO main digestemails - digesting [email protected]
INFO main digestemails - extracting attachments
INFO main digestemails - no attachments or no attachments supported
INFO main digestemails - updating database
INFO main digestemails - email -> COMPLETED folder
INFO main digestemails -  

I would like a time stamp per log message ie

INFO 2008-12-25 13:14:00 digestemails - email -> COMPLETED folder

here is my log4j config file

log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=c:\development\DCMail\logs\digestlogfolder\digest-logfile.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n 

How do I do it?

3 Answer