| 1 | ########################################################################### | ||||||||||
| 2 | # | ||||||||||
| 3 | # Handle.pm | ||||||||||
| 4 | # | ||||||||||
| 5 | # Copyright (C) 1999 Raphael Manfredi. | ||||||||||
| 6 | # Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org; | ||||||||||
| 7 | # all rights reserved. | ||||||||||
| 8 | # | ||||||||||
| 9 | # See the README file included with the | ||||||||||
| 10 | # distribution for license information. | ||||||||||
| 11 | # | ||||||||||
| 12 | ########################################################################## | ||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | require Log::Agent::Channel; | |||||||||
| 16 | 1 | require Log::Agent::Prefixer; | |||||||||
| 17 | 1 | require Log::Agent::File::Native; | |||||||||
| 18 | |||||||||||
| 19 | ######################################################################## | ||||||||||
| 20 | package Log::Agent::Channel::Handle; | ||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | use vars qw(@ISA); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | @ISA = qw(Log::Agent::Channel Log::Agent::Prefixer); | |||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | use Log::Agent::Stamping; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | # | ||||||||||
| 29 | # ->make -- defined | ||||||||||
| 30 | # | ||||||||||
| 31 | # Creation routine. | ||||||||||
| 32 | # | ||||||||||
| 33 | # Attributes (and switches that set them): | ||||||||||
| 34 | # | ||||||||||
| 35 | # prefix the application name | ||||||||||
| 36 | # stampfmt stamping format ("syslog", "date", "own", "none") or closure | ||||||||||
| 37 | # showpid whether to show pid after prefix in [] | ||||||||||
| 38 | # handle I/O glob or IO::Handle object | ||||||||||
| 39 | # no_ucfirst don't capitalize first letter of message when no prefix | ||||||||||
| 40 | # no_prefixing don't prefix logs | ||||||||||
| 41 | # no_newline never append any newline character at the end of messages | ||||||||||
| 42 | # | ||||||||||
| 43 | # Other attributes: | ||||||||||
| 44 | # | ||||||||||
| 45 | # crlf the new-line marker for this OS ("\n" on UNIX) | ||||||||||
| 46 | # | ||||||||||
| 47 | 2 | ▶ | sub make { | ||||||||
|
Subroutine
make: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||
| 48 | 2 | my $self = bless {}, shift; | |||||||||
| 49 | 2 | my (%args) = @_; | |||||||||
| 50 | |||||||||||
| 51 | my %set = ( | ||||||||||
| 52 | -prefix => \$self->{'prefix'}, | ||||||||||
| 53 | -stampfmt => \$self->{'stampfmt'}, | ||||||||||
| 54 | -showpid => \$self->{'showpid'}, | ||||||||||
| 55 | -handle => \$self->{'handle'}, | ||||||||||
| 56 | -no_ucfirst => \$self->{'no_ucfirst'}, | ||||||||||
| 57 | -no_prefixing => \$self->{'no_prefixing'}, | ||||||||||
| 58 | 2 | -no_newline => \$self->{'no_newline'}, | |||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 2 | ▶ | while (my ($arg, $val) = each %args) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 8 | my $vset = $set{lc($arg)}; | |||||||||
| 63 | 8 | ▶ | unless (ref $vset) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | require Carp; | |||||||||
| 65 | 0 | Carp::croak("Unknown switch $arg"); | |||||||||
| 66 | } | ||||||||||
| 67 | 8 | $$vset = $val; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | # | ||||||||||
| 71 | # Initialize proper time-stamping routine. | ||||||||||
| 72 | # | ||||||||||
| 73 | |||||||||||
| 74 | 2 | ▶ | $self->{'stampfmt'} = stamping_fn($self->stampfmt) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | unless ref $self->stampfmt eq 'CODE'; | ||||||||||
| 76 | |||||||||||
| 77 | 2 | ▶ | $self->{'crlf'} = $^O =~ /^dos|win/i ? "\r\n" : "\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | |||||||||||
| 79 | 2 | return $self; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | # | ||||||||||
| 83 | # Local attribute access | ||||||||||
| 84 | # | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub handle { $_[0]->{'handle'} } | ||||||||
|
Subroutine
handle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | |||||||||||
| 88 | # | ||||||||||
| 89 | # ->write -- defined | ||||||||||
| 90 | # | ||||||||||
| 91 | # Write logstring to the file. | ||||||||||
| 92 | # Priority is ignored by this channel. | ||||||||||
| 93 | # | ||||||||||
| 94 | 2 | ▶ | sub write { | ||||||||
|
Subroutine
write: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 95 | 2 | my $self = shift; | |||||||||
| 96 | 2 | my ($priority, $logstring) = @_; | |||||||||
| 97 | |||||||||||
| 98 | # | ||||||||||
| 99 | # This routine is called often... | ||||||||||
| 100 | # Bypass the attribute access routines. | ||||||||||
| 101 | # | ||||||||||
| 102 | |||||||||||
| 103 | 2 | my $handle = $self->{handle}; | |||||||||
| 104 | 2 | ▶ | return unless defined $handle; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | |||||||||||
| 106 | 2 | my $prefix = ''; | |||||||||
| 107 | $prefix = $self->prefixing_string(\$logstring) | ||||||||||
| 108 | 2 | ▶ | unless $self->{no_prefixing}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 2 | my $crlf = ''; | |||||||||
| 111 | 2 | ▶ | $crlf = $self->{crlf} unless $self->{no_newline}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | |||||||||||
| 113 | 2 | print $handle join '', $prefix, $logstring, $crlf; | |||||||||
| 114 | |||||||||||
| 115 | 2 | return; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | # | ||||||||||
| 119 | # ->close -- defined | ||||||||||
| 120 | # | ||||||||||
| 121 | # | ||||||||||
| 122 | 2 | ▶ | sub close { | ||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 123 | 2 | my $self = shift; | |||||||||
| 124 | 2 | $self->{handle} = undef; | |||||||||
| 125 | |||||||||||
| 126 | # | ||||||||||
| 127 | # Do nothing on the handle itself. | ||||||||||
| 128 | # We did not open the thing, we don't get to close it. | ||||||||||
| 129 | # | ||||||||||
| 130 | |||||||||||
| 131 | 2 | return; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | 1 | 1; # for require | |||||||||
| 135 | __END__ | ||||||||||