View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Giacomo Montagner > Tie-Syslog > Tie::Syslog



Annotate this POD


Open  0
View/Report Bugs
Module Version: 2.04.03   Source  


Tie::Syslog - Tie a filehandle to Syslog.



v2.00 is a complete rewrite of Tie::Syslog. If you used v1.x and something broke after upgrade, please report the problem back and I'll try to fix it asap. Thanks.


    use Tie::Syslog;

    $Tie::Syslog::ident  = "my logging tag";
    $Tie::Syslog::logopt = "pid,ndelay";

    # Tie STDOUT to Syslog, so that every print()ed message will be logged
    tie *STDOUT, 'Tie::Syslog', {
        facility => 'LOG_LOCAL0',
        priority => 'LOG_INFO',

    # Now tie STDERR also, getting parameters from the tied STDOUT
    tie *STDERR, { tied *STDOUT };

    # ...or...

    # tie STDERR with defaults from tied STDOUT, but override priority:
    tie *STDERR, { tied *STDOUT }, {
        priority => 'LOG_ERR',

    # Compatibility with old configuration style:

    tie *STDOUT, 'Tie::Syslog', 
        'local0.error',         # facility.loglevel
        'myname',               # identity 
        'pid,ndelay',           # Other Sys::Syslog options, comma-separated
        'unix';                 # setlogsock socket type: unix or inet

    tie *STDERR, 'Tie::Syslog', 
        'local0.warning',       # facility.loglevel
        'myname',               # USE THE SAME AS ABOVE!
        'pid,ndelay',           # USE THE SAME AS ABOVE!
        'unix';                 # USE THE SAME AS ABOVE!

    # Tying by copying from another tied handle is not supported in 
    # old-compatibility-mode

    # old-compatibility-mode defaults to 'local0.error'

    # socket type is IGNORED


This module lets you tie a filehandle to Sys::Syslog, providing an easy way to redirect messages to system logs.

    $Tie::Syslog::ident  = 'DEBUG :: myprocess';
    $Tie::Syslog::logopt = 'pid,ndelay';

    tie *DEBUG, 'Tie::Syslog', {
        facility => 'LOG_LOCAL0',
        priority => 'LOG_DEBUG',

    print DEBUG "This is a debug message - won't probably get to system logs.";

By tying STDOUT and/or STDERR you can easily redirect all messages to system logs, including those of warn() and die().

Tipically, you'll want to tie STDOUT with a lower priority than STDERR.



Identity set for logging. This is a global option, and will be valid from the moment you set it onward. The default value is the last field of $0 split on '/'.


Logging options. These are standard Sys::Syslog logopts. See Sys::Syslog man page for details. This is a global option, default is 'pid,ndelay'.


One of the default Sys::Syslog facilities available on your system. See Sys::Syslog man page for details. You can have different facilities for different filehandles, but this is not recommended, and will prevent Tie::Syslog from calling closelog() (see "CAVEATS" for details).

You can redefine a the facility for a given filehandle on the fly:

    my $fho = tied *MYFH;

    # better: 

    (tied *MYFH)->facility('LOG_MAIL');

    # better yet: don't do it

but please note that this is against Sys::Syslog rule:


One of the default Sys::Syslog priorities available on your system. See Sys::Syslog man page for details. You can have different priorities for different filehandles.

You can redefine the priority for a given filehandle on the fly:

    my $fho = tied *MYFH;

    # better: 

    (tied *MYFH)->priority('LOG_CRIT');



Log priorities, facilities and valid values for logopt are listed in Sys::Syslog man page.

Read syslog(3) for details on syslog.


Broc Seib, bseib at - up to 1.07

Giacomo Montagner, <kromg at> - from 2.00 onward.


Please report any bugs or feature requests to bug-tie-syslog at, or through the web interface at I'will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Tie::Syslog

You can also look for information at:


Many thanks to Broc Seib, who wrote this module back in 1999.


Copyright (C) 1999-2001 Broc Seib

Copyright (C) 2012 Giacomo Montagner.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See for more information.

syntax highlighting: