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