in reply to Re: Scope of Filehandle inside Subroutine?
in thread Scope of Filehandle inside Subroutine?

When it comes to logging, I more and more tend to delegate it, like I do already for data storage: I put all data into an RDBMS, use DBI, and don't have to care any longer about locking, concurrency and all that stuff. The RBDMS does that for me.

For logging, syslog is a common approach, but it is too "common". Each and every program writes into syslog, leaving a big heap of junk that has to be filtered manually for information.

So, each application better uses its own log. Log rotation can be solved differently. There are several log rotating utilities that send signals and rename files, hoping that no data is lost and the service stays available during the transition. Apache comes with a rotatelogs utility that is used in a pipe, copying its STDIN to several timestamped files in a given directory. Unfortunately, the exact filenames are hard to predict, because they depend on the exact start time of rotatelogs.

djb's multilog program can do even more: It can automatically add timestamps, it automatically rotates the log files while keeping a constant name for the current log file, it can limit the number of old log files, and it can filter the log data. Together with other parts of the daemontools, writing a background service is no longer harder than writing a simple command line application. supervise takes care of starting, stopping, and restarting the application when needed, and all you need for logging is a simple write operation to STDERR (or maybe STDOUT), like warn, die, or print STDERR. (See the djb way for details.)

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: Scope of Filehandle inside Subroutine?
by Marshall (Canon) on Aug 05, 2009 at 00:17 UTC
    Great post!

    the OP's main problem is not what is scope of this or that (although that is a completely valid and relevant question). The main issue appears to be: how to do log rotation in a way that doesn't loose data and will run reliably 24/7. I think your suggestions are on target.