salonmonk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks !

I've just been given what seems like a simple enough problem, but I'm hoping some of you better travelled Perl hackers might be able to give me some advice or problems that you might have come across.

Basically I need to write a logger. It will be taking input from a serial port and dumping its data out to a file. The only problem I can see is that another process might want to look at that log file every so often, so I need to flush to the log every so often.

Data might come from the serial port very quickly - so I'm wondering how I prevent buffers of various kinds getting full.

What kind of things should I look out for ? Or is there a module (I'm almost cringing right now because I haven't yet looked) that will do all this without me writing a line of code in anger....

anything very much appreciated. ** off to check the wonderland; CPAN.

Replies are listed 'Best First'.
Re: Persistent logging...
by andyford (Curate) on Mar 11, 2007 at 11:51 UTC
Re: Persistent logging...
by zentara (Cardinal) on Mar 11, 2007 at 11:57 UTC
Re: Persistent logging...
by ides (Deacon) on Mar 11, 2007 at 15:55 UTC

    Since you seem to be just taking data and pushing it off to disk, you might want to consider Sys::Syslog and use a syslog or syslog-ng daemon.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

      A related program is www.cronolog.org . You might be able to use a command line like this one instead of writing any code:
      cat /dev/ttyS0 | cronolog /logs/serial_data_%Y-%m-%d
      The above line will automatically create one log file per day and date-stamp it with the format YYYY-MM-DD .
Re: Persistent logging...
by fmerges (Chaplain) on Mar 12, 2007 at 10:16 UTC

    Hi,

    use IO::Handle; open my $Log, '>>', 'file.dat'; $Log->autoflush(1); while(<$serial>) { print { $Log } $_; }

    If you need something more sophisticated (like dispatchers, file quota, etc), take a look at Log::Dispatch and Log::Log4Perl

    Regards,

    fmerges at irc.freenode.net