• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to handle log rotation? (/var/adm/messages)

 
Yarik Chinskiy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a log monitor. The monitor has to be able to handle log rotations.
I tried to do a rotation manually in windows by renaming the original log to another name and creating a new log file. The OS complains that the file is in use by another application.
Looks like java locks the file. How can i make it work?

Thank you.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably need to make sure the classes which control writing to the file have been properly closed before you try to rename. Using the logging classes in JDK 1.4, it should be something like this:

Here logFile and savedLogFile are both File objects representing the name of the current log file, and the file once it's been renamed for archiving, respectively.
 
Yarik Chinskiy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The log is created by a 3 party. For example syslogd
I have no control over the rename or the writing. All i need to do is to read and parse.
At the same time i do not want to interfear with the logging.

BTW i use Java 1.3
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!