0

I would like to rotate logs that are already being managed by logrotate.

However logrotate used to rotate log only on daily basis as it is purely a CRON task.

I would like to execute logrotate when ever the file size exceeds the size specified in the size parameter for logrotate config file. I am planning to implement the same by monitoring the log files and execute the logrotate when ever the size of the log file exceeds the size specified in logrotate config.

What is the optimal way to do this in java?

Balachandar
  • 1,538
  • 3
  • 16
  • 25
  • Unix `logrotate` with `size=100k` should do, but I might be on the wrong "logrotate." – Joop Eggen Mar 24 '15 at 09:21
  • since this logrotate executes as cron task it would execute only at specified time. By that time if the size of file execeeds value configured for size, then the file will be rotated. But my requiredment is to call this logrotate whenever the size of file execeeds the configured value. – Balachandar Mar 24 '15 at 09:24
  • What is writing this log file? Some logging systems have built-in log rotating abilities. – Kenster Mar 24 '15 at 14:02
  • Our's is a legecy code and modifying to use any logging framework is a tedious task to implement and do testing. hence i opted to stick with existing functionality by adding logic to invoke logrotate. – Balachandar Mar 25 '15 at 04:00

1 Answers1

0

One way of doing this is to use WatchService then act when the file is being written and the size is greater than the threshold.

Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
  • Thank you.. would try it – Balachandar Mar 24 '15 at 10:13
  • 1
    hi, I could see that this api is introduced from jdk1.7. Our build process uses jdk1.6 hence can't use WatchService. In case if you know any other equivalent and optimal way in jdk1.6 please do let me know. – Balachandar Mar 25 '15 at 05:05