Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?



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

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

Browse other questions tagged or ask your own question.