What's the "most correctest" way to open, use/call, and close the Sys::Syslog library in one's OOP module/class?
I've used Sys::Syslog many times in scripts, and it's quite obvious and simple how to use.
But I've got an existing class, and I'm wondering how to best go about utilzing Sys::Syslog...
Should I put the:
setlogsock( 'unix' );
openlog( 'FooClass', 'pid', 'local6' );
lines in a BEGIN block?
and the:
closelog()
in an END block?
Something like:
package FooClass;
use strict;
use warnings;
use Sys::Syslog qw( :DEFAULT setlogsock );
BEGIN {
setlogsock( 'unix' );
openlog( 'IPScan', 'pid', 'local6' );
}
END { closelog() }
sub new {
my $invocant = shift;
my $class = ref( $invocant ) || $invocant;
my %args = @_;
my $self = bless { %args }, $class;
syslog( 'info', "blah blah blah" );
return $self;
}
sub foobar {
my $self = shift;
syslog( 'info', 'foobarred' );
# do stuff
}
1;
Any help/advice is appreciated, thanks!
UPDATE:
When I attempt the above described pattern, I get an error message to the extent of:
no connection to syslog available
- _PATH_LOG not available in syslog.h at /path/to/FooClass.pm
+line 24
where line 24 is the first attempt to use the syslog call, for instance, at:
syslog( 'info', "blah blah blah" );
... in the new() method.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.