File Coverage

blib/lib/XAS/Lib/Log/Syslog.pm
Criterion Covered Total %
statement 6 18 33.3
branch n/a
condition n/a
subroutine 2 5 40.0
pod 2 2 100.0
total 10 25 40.0


line stmt bran cond sub pod time code
1             package XAS::Lib::Log::Syslog;
2              
3             our $VERSION = '0.01';
4              
5 1     1   1477 use Sys::Syslog qw(:standard :extended);
  1         5295  
  1         135  
6              
7             use XAS::Class
8 1         10 debug => 0,
9             version => $VERSION,
10             base => 'XAS::Base',
11             utils => ':validation level2syslog',
12             constants => 'HASHREF',
13 1     1   5 ;
  1         1  
14              
15             # ----------------------------------------------------------------------
16             # Public Methods
17             # ----------------------------------------------------------------------
18              
19             sub output {
20 0     0 1   my $self = shift;
21 0           my ($args) = validate_params(\@_, [
22             { type => HASHREF }
23             ]);
24              
25 0           my $priority = level2syslog(lc($args->{'priority'}));
26 0           my $message = sprintf('%s', $args->{'message'});
27              
28 0           syslog($priority, $message);
29              
30             }
31              
32             sub DESTROY {
33 0     0     my $self = shift;
34              
35 0           closelog();
36              
37             }
38              
39             # ----------------------------------------------------------------------
40             # Private Methods
41             # ----------------------------------------------------------------------
42              
43             sub init {
44 0     0 1   my $class = shift;
45              
46 0           my $self = $class->SUPER::init(@_);
47              
48 0           setlogsock('unix');
49 0           openlog($self->env->script, 'pid', $self->env->log_facility);
50              
51 0           return $self;
52              
53             }
54              
55             1;
56              
57             __END__
58              
59             =head1 NAME
60              
61             XAS::Lib::Log::Syslog - A class for logging syslog
62              
63             =head1 DESCRIPTION
64              
65             This module is for logging to syslog.
66              
67             =head1 METHODS
68              
69             =head2 new
70              
71             This method initializes syslog. Sets the process, facility and requests that
72             the pid be included.
73              
74             =head2 output($hashref)
75              
76             This method translate the log level to an appropriate syslog priority and
77             writes out the log line. The translation is a follows:
78              
79             info => 'info',
80             error => 'err',
81             warn => 'warning',
82             fatal => 'alert',
83             trace => 'notice',
84             debug => 'debug'
85              
86             =head2 destroy
87              
88             Closes the connection to syslog.
89              
90             =head1 SEE ALSO
91              
92             =over 4
93              
94             =item L<XAS::Lib::Log|XAS::Lib::Log>
95              
96             =item L<XAS|XAS>
97              
98             =back
99              
100             =head1 AUTHOR
101              
102             Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             Copyright (c) 2012-2014 Kevin L. Esteb
107              
108             This is free software; you can redistribute it and/or modify it under
109             the terms of the Artistic License 2.0. For details, see the full text
110             of the license at http://www.perlfoundation.org/artistic_license_2_0.
111              
112             =cut