Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Persistent logging...

by salonmonk (Beadle)
on Mar 11, 2007 at 11:05 UTC ( [id://604209]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://604209]
Approved by andyford
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2025-12-08 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (88 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.