Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Catching perl warnings and errors

by CukiMnstr (Deacon)
on May 26, 2003 at 08:03 UTC ( #260794=note: print w/replies, xml ) Need Help??

in reply to Catching perl warnings and errors

Errors and warnings (in UNIX, I don't know how this works in Windows) are printed to STDERR (standard error). STDERR is attached to the console by default, so if you want to print errors/warnings somewhere else, you just have to redirect STDERR (filehandle 2):
$ perl -Mstrict -e '$test = "foo"'
will print
Global symbol "$test" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
to the console, but
$ perl -Mstrict -e '$test = "foo"' 2> error.log
will print the error to file ./error.log. Check your shell's manpage for details on redirecting STDERR.

hope this helps,

Update: as for using syslog to log the errors, I don't know if you can do this, since as far as I can remember, you use a specific system call to do that: syslog(3).

Update #2: a quick question in #debian @ and I have something else: check the logger command, which is a "shell command interface to the syslog(3) system log module" (from the manpage).

Replies are listed 'Best First'.
Re: Re: Catching perl warnings and errors
by hotshot (Prior) on May 26, 2003 at 08:33 UTC
    I use perl module Sys::Syslog for sending any messages to syslog, it work great. I only want to catch perl errors (from within my scripts not by redirecting it from the command line)and send them to syslog the same way.

      oh. I understood something else from your first post...

      There are many ways to catch exceptions. You could use eval(), but using eval() will not work for warnings from the compiler, from the POD:

      Beware that using "eval" neither silences perl from printing warnings +to STDERR, nor does it stuff the text of warning messages into $@.
      Or you can use Error as nite_man suggests, but I just made a couple of tests and read the docs and compiler warnings don't seem to be handled by it.

      hope this helps,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://260794]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-02-29 01:56 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (128 votes). Check out past polls.