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

Hi Monks!
I need to develop a error module to be used by all the Perl programs that I use, I need to log errors like, warnings, failed odbc calls, a user entering an account number and it's not found etc...You got the idea.
I would like some examples if possible, and how to use this kind of module through out all the files ( Perl programs), and if there would be an easy way to do it.
Thanks for the Help!

Replies are listed 'Best First'.
Re: Log Files Module
by coreolyn (Parson) on Dec 28, 2005 at 16:39 UTC

      Seconded. I keep looking at other logging modules because log4perls configuration syntax and general appearance just seems strange and unperlish to me, but I keep going back to it because for pure functionality it has no rival.


      A computer is a state machine. Threads are for people who can't program state machines. -- Alan Cox
        I keep looking at other logging modules because log4perls configuration syntax and general appearance just seems strange and unperlish to me
        You might then want to use Log4perl's easy mode, which is as perlish as it could get:
        use Log::Log4perl qw(:easy); Log::Log4perl->easy_init({ level => $INFO, file => ">>foo.txt" }); DEBUG "Doesn't make it."; INFO "Hella!\n";
Re: Log Files Module
by kprasanna_79 (Hermit) on Dec 28, 2005 at 17:22 UTC
    Hi,

    Rather than looking for a specific module to redirect a your error and warnings, why cant you simple write a small module which redirects your STDERR and STDOUT to a log file. tie that module in your program.

    Is my suggestion acceptable. Because i did this way and i find it very useful and handy because i can tune accordingly to my need.

    A small psuedo code for you...it will be help full..i think..

    sub setlog { unless( ($log = tie(*STDOUT, 'your::module', ">>$LOGFILE")) +) } -------------- your::module ------------- sub PRINT { $fh # file handle my $line = (caller(0))[2]; syswrite $fh, sprintf("[ %-18.18s %s %4.4s ] %s %s", "$script $lin +e", }
    -Prasanna.K
      Like your approach, I am going to do some tests based on this code style.
      Would this work in a windows environment?
Re: Log Files Module
by philcrow (Priest) on Dec 28, 2005 at 17:30 UTC
    If you're on a unix flavor, try Sys::Syslog. I explained a bit of how to do this in Re: Sys:syslog.

    Phil

      No, unfortunate it is windows.
        So...Win32::EventLog (included with ActiveState)?