• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Clear old logs

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing the following in log4j.properties

log4j.rootLogger=DEBUG, A
log4j.logger.com.datacorrection.updateWkfHistory=DEBUG
log4j.appender.A=org.apache.log4j.FileAppender
log4j.appender.A.File=c:\\TEMP\\a.log
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n

When I execute my Java program for the first time the logs are added to a.log. But when I execute the program again, the logs are appended to the existing logs only. This makes the log file very big and difficult to understand. Is it possible to create a new log file everytime code is executed.

Secondly, Can I print the same logs to console as well which are being written to log file.

Thank you
 
Sheriff
Posts: 28382
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest using one of the other appenders, like DailyFileAppender or RollingFileAppender... I'm not looking at the API documentation as I guess these names, so I may have them wrong, but you should look there.

And yes, there's a ConsoleAppender too.

And since this post appears to be about log4j I will move it to the appropriate forum.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition to what Paul mentioned, look at the "append" property of these appenders. You can set it to false, if you want to recreate the log files every time you run your program.
 
reply
    Bookmark Topic Watch Topic
  • New Topic