line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# <@LICENSE> |
2
|
|
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more |
3
|
|
|
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
4
|
|
|
|
|
|
|
# this work for additional information regarding copyright ownership. |
5
|
|
|
|
|
|
|
# The ASF licenses this file to you under the Apache License, Version 2.0 |
6
|
|
|
|
|
|
|
# (the "License"); you may not use this file except in compliance with |
7
|
|
|
|
|
|
|
# the License. You may obtain a copy of the License at: |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
12
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
15
|
|
|
|
|
|
|
# limitations under the License. |
16
|
|
|
|
|
|
|
# </@LICENSE> |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Mail::SpamAssassin::Logger::Stderr - log to standard error |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
loadplugin Mail::SpamAssassin::Logger::Stderr |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
package Mail::SpamAssassin::Logger::Stderr; |
31
|
|
|
|
|
|
|
|
32
|
44
|
|
|
44
|
|
296
|
use strict; |
|
44
|
|
|
|
|
88
|
|
|
44
|
|
|
|
|
1473
|
|
33
|
44
|
|
|
44
|
|
262
|
use warnings; |
|
44
|
|
|
|
|
110
|
|
|
44
|
|
|
|
|
1416
|
|
34
|
|
|
|
|
|
|
# use bytes; |
35
|
44
|
|
|
44
|
|
257
|
use re 'taint'; |
|
44
|
|
|
|
|
76
|
|
|
44
|
|
|
|
|
1582
|
|
36
|
|
|
|
|
|
|
|
37
|
44
|
|
|
44
|
|
3844
|
use POSIX (); |
|
44
|
|
|
|
|
43367
|
|
|
44
|
|
|
|
|
844
|
|
38
|
44
|
|
|
44
|
|
265
|
use Time::HiRes (); |
|
44
|
|
|
|
|
90
|
|
|
44
|
|
|
|
|
3891
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our @ISA = (); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# ADDING OS-DEPENDENT LINE TERMINATOR - BUG 6456 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Using Mail::SpamAssassin::Util::am_running_on_windows() leads to circular |
45
|
|
|
|
|
|
|
# dependencies. So, we are duplicating the code instead. |
46
|
44
|
|
|
44
|
|
301
|
use constant RUNNING_ON_WINDOWS => ($^O =~ /^(?:mswin|dos|os2)/oi); |
|
44
|
|
|
|
|
100
|
|
|
44
|
|
|
|
|
19370
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $eol = "\n"; |
49
|
|
|
|
|
|
|
if (RUNNING_ON_WINDOWS) { |
50
|
|
|
|
|
|
|
$eol = "\r\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
44
|
|
|
44
|
0
|
107
|
my $class = shift; |
55
|
|
|
|
|
|
|
|
56
|
44
|
|
33
|
|
|
358
|
$class = ref($class) || $class; |
57
|
44
|
|
|
|
|
94
|
my $self = { }; |
58
|
44
|
|
|
|
|
99
|
bless ($self, $class); |
59
|
|
|
|
|
|
|
|
60
|
44
|
|
|
|
|
100
|
my %params = @_; |
61
|
44
|
|
|
|
|
207
|
$self->{timestamp_fmt} = $params{timestamp_fmt}; |
62
|
|
|
|
|
|
|
|
63
|
44
|
|
|
|
|
193
|
return($self); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub log_message { |
67
|
0
|
|
|
0
|
0
|
0
|
my ($self, $level, $msg, $ts) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
my $timestamp; |
70
|
0
|
|
|
|
|
0
|
my $fmt = $self->{timestamp_fmt}; |
71
|
0
|
0
|
|
|
|
0
|
my $now = defined $ts ? $ts : Time::HiRes::time; |
72
|
0
|
0
|
|
|
|
0
|
if (!defined $fmt) { |
|
|
0
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# default since 3.3.0 |
74
|
0
|
|
|
|
|
0
|
my $datetime = POSIX::strftime("%b %d %H:%M", localtime($now)); |
75
|
0
|
0
|
|
|
|
0
|
utf8::encode($datetime) if utf8::is_utf8($datetime); # Bug 7305 |
76
|
0
|
|
|
|
|
0
|
$timestamp = sprintf("%s:%06.3f", $datetime, $now-int($now/60)*60); |
77
|
|
|
|
|
|
|
# Bug 6329: %e is not in a POSIX standard, use %d instead and edit |
78
|
0
|
|
|
|
|
0
|
local $1; $timestamp =~ s/^(\S+\s+)0/$1 /; |
|
0
|
|
|
|
|
0
|
|
79
|
|
|
|
|
|
|
} elsif ($fmt eq '') { |
80
|
0
|
|
|
|
|
0
|
$timestamp = ''; |
81
|
|
|
|
|
|
|
} else { |
82
|
0
|
|
|
|
|
0
|
$timestamp = POSIX::strftime($fmt, localtime($now)); |
83
|
|
|
|
|
|
|
} |
84
|
0
|
0
|
|
|
|
0
|
$timestamp .= ' ' if $timestamp ne ''; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
my($nwrite) = syswrite(STDERR, sprintf("%s[%d] %s: %s%s", |
87
|
|
|
|
|
|
|
$timestamp, $$, $level, $msg, $eol)); |
88
|
0
|
0
|
|
|
|
0
|
defined $nwrite or warn "error writing to log file: $!"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub close_log { |
92
|
44
|
|
|
44
|
0
|
283
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |