Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Catching perl warnings and errors

by CukiMnstr (Deacon)
on May 26, 2003 at 08:03 UTC ( [id://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 @ freenode.net 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.

    Hotshot
      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found