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

i have installed Sys::Syslog,but the log files is not created actually i want a error msg if i not give ant=y argument in it,please help me what changes i have to make in code?

use Sys::Syslog; $filename=$ARGV[0]; $name="system.log"; openlog($name, "ndelay,pid", "local0"); if (!defined $ARGV[0]) { syslog("info", "$filename is not there"); };

Replies are listed 'Best First'.
Re: not creating log files
by karlgoethebier (Abbot) on Feb 03, 2014 at 14:41 UTC

    Try something like this:

    sub slog { my ( $prg, $priority, $msg ) = @_; return unless ($priority =~ /info|err|debug/); openlog( $prg, 'pid', 'user' ); syslog( $priority, $msg ); closelog(); return 1; }

    Use it like this:

    my $prg = $0; my $message =qq(Something weird happend!); slog( $prg, 'err', $message )

    I assume you use Linux. So the message should be in /var/log/messages

    On windows run eventvwr

    .

    Hope that helps. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      But i want the log file to create,where can i find that

        /var/log/messages is a file. The default place to go for log messages on Linux and IHMO the best in most cases (still assuming you are on Linux). If you are on Windows the Event Log or what ever they call it in English, is a good place too.

        Type file /var/log/messages and you will see /var/log/messages: ASCII English text, with very long lines. Or i hope so ;-) Please see also Sys::Syslog and syslog as well as the hints marto gave below (perhaps you should start there...)

        I mentioned already in the CB that you should consider just to print to STDOUT and STDERR and then redirect the stuff to a file (your_prg.pl > your_log.log). By far the easiest solution to begin. See redirections for further information about this. The links marto provided should be helpful for learning how to do so.

        EDIT: fixed little typo...

        Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»