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.