| 1 | |||
| 2 | package Role::Log::Syslog::Fast; | ||
| 3 | |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use Log::Syslog::Fast 0.55 ':all'; | ||
| 7 | use List::Util qw(first); | ||
| 8 | |||
| 9 | # ABSTRACT: A Logging role for Moose on Log::Syslog::Fast | ||
| 10 | our $VERSION = '0.14'; # VERSION | ||
| 11 | |||
| 12 | has '_proto' => ( | ||
| 13 | is => 'rw', | ||
| 14 | isa => 'Int', | ||
| 15 | default => LOG_UNIX | ||
| 16 | ); | ||
| 17 | |||
| 18 | has '_hostname' => ( | ||
| 19 | is => 'rw', | ||
| 20 | isa => 'Str', | ||
| 21 | lazy => 1, | ||
| 22 | default => sub { | ||
| 23 | my $options = [ '/dev/log', '/dev/klog', '/var/run/syslog' ]; | ||
| 24 | my $found = first {-r} @$options; | ||
| 25 | return $found if $found; | ||
| 26 | } | ||
| 27 | ); | ||
| 28 | |||
| 29 | has '_port' => ( | ||
| 30 | is => 'rw', | ||
| 31 | isa => 'Int', | ||
| 32 | default => 514 | ||
| 33 | ); | ||
| 34 | |||
| 35 | has '_facility' => ( | ||
| 36 | is => 'rw', | ||
| 37 | isa => 'Int', | ||
| 38 | default => LOG_LOCAL0 | ||
| 39 | ); | ||
| 40 | |||
| 41 | has '_severity' => ( | ||
| 42 | is => 'rw', | ||
| 43 | isa => 'Int', | ||
| 44 | default => LOG_INFO | ||
| 45 | ); | ||
| 46 | |||
| 47 | has '_sender' => ( | ||
| 48 | is => 'rw', | ||
| 49 | isa => 'Str', | ||
| 50 | default => 'localhost' | ||
| 51 | ); | ||
| 52 | |||
| 53 | has '_name' => ( | ||
| 54 | is => 'rw', | ||
| 55 | isa => 'Str', | ||
| 56 | default => 'MooseX-Log-Syslog-Fast' | ||
| 57 | ); | ||
| 58 | |||
| 59 | has '_logger' => ( | ||
| 60 | is => 'ro', | ||
| 61 | isa => 'Log::Syslog::Fast', | ||
| 62 | lazy => 1, | ||
| 63 | default => sub { | ||
| 64 | my $self = shift; | ||
| 65 | return Log::Syslog::Fast->new( | ||
| 66 | $self->_proto, $self->_hostname, $self->_port, $self->_facility, | ||
| 67 | $self->_severity, $self->_sender, $self->_name | ||
| 68 | ); | ||
| 69 | } | ||
| 70 | ); | ||
| 71 | |||
| 72 | sub log { | ||
| 73 | my ( $self, $msg, $time ) = @_; | ||
| 74 | return $time ? $self->_logger->send( $msg, $time ) : $self->_logger->send($msg); | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; | ||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | =pod | ||
| 82 | |||
| 83 | =head1 NAME | ||
| 84 | |||
| 85 | Role::Log::Syslog::Fast - A Logging role for Moose on Log::Syslog::Fast | ||
| 86 | |||
| 87 | =head1 VERSION | ||
| 88 | |||
| 89 | version 0.14 | ||
| 90 | |||
| 91 | =head1 SYNOPSIS | ||
| 92 | |||
| 93 | { | ||
| 94 | package ExampleLog; | ||
| 95 | |||
| 96 | use Moose; | ||
| 97 | with 'Role::Log::Syslog::Fast'; | ||
| 98 | |||
| 99 | sub BUILD { | ||
| 100 | my $self = shift; | ||
| 101 | $self->_hostname('/var/run/syslog'); | ||
| 102 | $self->_name('Example'); | ||
| 103 | } | ||
| 104 | |||
| 105 | sub test { | ||
| 106 | my $self = shift; | ||
| 107 | $self->log('foo'); | ||
| 108 | } | ||
| 109 | |||
| 110 | } | ||
| 111 | |||
| 112 | my $obj = new ExampleLog; | ||
| 113 | |||
| 114 | $obj->test; | ||
| 115 | |||
| 116 | =head1 DESCRIPTION | ||
| 117 | |||
| 118 | A logging role building a very lightweight wrapper to L<Log::Syslog::Fast> for use with L<Moose> classes. | ||
| 119 | |||
| 120 | =head1 METHOD | ||
| 121 | |||
| 122 | =head2 log | ||
| 123 | |||
| 124 | (message, [time]) | ||
| 125 | |||
| 126 | =head1 SEE ALSO | ||
| 127 | |||
| 128 | L<Log::Syslog::Fast>, L<Log::Syslog>, L<Moose> | ||
| 129 | |||
| 130 | =head1 BUGS AND LIMITATIONS | ||
| 131 | |||
| 132 | Please report any bugs or feature requests to bug-moosex-log-syslog-fast@rt.cpan.org, or through the web interface at http://rt.cpan.org. | ||
| 133 | |||
| 134 | Or come bother us in #moose on irc.perl.org. | ||
| 135 | |||
| 136 | =head1 AUTHOR | ||
| 137 | |||
| 138 | Thiago Rondon <thiago@aware.com.br> | ||
| 139 | |||
| 140 | =head1 LICENSE AND COPYRIGHT | ||
| 141 | |||
| 142 | This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 143 | |||
| 144 | =head1 AUTHOR | ||
| 145 | |||
| 146 | Thiago Rondon <thiago@nsms.com.br> | ||
| 147 | |||
| 148 | =head1 COPYRIGHT AND LICENSE | ||
| 149 | |||
| 150 | This software is copyright (c) 2011 by Thiago Rondon. | ||
| 151 | |||
| 152 | This is free software; you can redistribute it and/or modify it under | ||
| 153 | the same terms as the Perl 5 programming language system itself. | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | |||
| 158 | __END__ | ||