Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use log4j to create rolling log files from my program. It writes to a log file until it reaches 256mb, and then it renames all the log files and creates a new log file and continues logging.

It is very useful for me to monitor these log files while my program runs, so I run "tail -f" on the log file to watch it in realtime.

The problem is occurs when the log rotation occurs, which does not happen at a predictable time. "Tail" is following the file with a particular handle, regardless of its name, so when the rotation occurs, tail is pointing to an old file that is no longer being logged to. If I stop and re-run the command, it will find the current file again.

How can I follow the most recent log file automatically? How can I follow a file with a given name, such that a log rotation will always show output from the newest file?

Thanks!

share

merged by Mark Henderson Jun 17 '11 at 3:10

This question was merged with Continuously monitor logs with tail that are occasionally rotated because it is an exact duplicate of that question.