• 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
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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: 27235
87
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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic