I have a piece of software that rotates its log files when it restarts. However, during development, I am restarting it a lot, so I would like to monitor the latest log file at any time.

If I start less normally - less program.log - and hit Shift-f to tail, when the log file is rotated, I carry on monitoring the old log file. I assume this is because the inode number stays the same and less has an open file handle to that inode.

Is it possible to monitor the latest activity on whatever log file is currently called program.log?

Specifically, I am working on Sun OS, so a solution that works there would be ideal.

Using tail:

-f, --follow[={name|descriptor}]
output appended data as the file grows; -f,
--follow, and --follow=descriptor are equivalent
-F same as --follow=name --retry
--retry keep trying to open a file even when it is or becomes
inaccessible; useful when following by name, i.e., with
--follow=name

The key is the --retry switch. This tells the tail command to keep retrying to follow a file by name. The -F switch does both a -f and a --retry.

Using less

As @StephaneChazela pointed out in the comments the following will not work.

tail -F program.log | less

The only other option you have is to use less directly assuming it supports the --follow-name switch and less the file directly, forgoing using tail completely.

I agree, I worked for years, it drives you nuts that the tooling is like 10 years old for some of the apps. Makes no sense. This site was invaluable for keeping your sanity on Solaris: sunfreeware.com/introduction.html
–
slm♦May 1 '13 at 8:43

if you want more sanity, check out pkgsrc.org :)
–
sendmoreinfoMay 1 '13 at 9:06

That won't work nicely. Because less will hang if you do "G" pr "F". Which you can interrupt by doing "Ctrl-C", but then it kills tail. You can then immune tail to Ctrl-C, but it's still not very usable.
–
Stéphane ChazelasMay 1 '13 at 9:47

With regards to GNU tail: Check out this for information about what tools should be available on any Solaris host. (Actually GNU tail is there by default in Solaris 11). Solaris sysadmins often make it harder for their users because they leave the install at the very bare-bone install while GNU tools for Solaris are actually these days available directly from Oracle or in some cases part of default install. No reason not to make it part of your install. No reason to go to 'unofficial' repos. See link.
–
unixhacker2010Jul 30 '13 at 20:19