line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TeX::AutoTeX::Log; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: Log.pm,v 1.10.2.5 2011/01/27 18:42:28 thorstens Exp $ |
5
|
|
|
|
|
|
|
# $Revision: 1.10.2.5 $ |
6
|
|
|
|
|
|
|
# $Source: /cvsroot/arxivlib/arXivLib/lib/TeX/AutoTeX/Log.pm,v $ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# $Date: 2011/01/27 18:42:28 $ |
9
|
|
|
|
|
|
|
# $Author: thorstens $ |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
86
|
|
13
|
|
|
|
|
|
|
### use warnings; |
14
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
162
|
|
15
|
2
|
|
|
2
|
|
15
|
use TeX::AutoTeX::Exception; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
20
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our ($VERSION) = '$Revision: 1.10.2.5 $' =~ m{ \$Revision: \s+ (\S+) }x; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
2325
|
use IO::Handle; #for autoflush |
|
2
|
|
|
|
|
15008
|
|
|
2
|
|
|
|
|
1204
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
1
|
|
my $that = shift; |
23
|
0
|
|
0
|
|
|
|
my $class = ref($that) || $that; |
24
|
0
|
|
|
|
|
|
my $self = { |
25
|
|
|
|
|
|
|
logfile => 'auto_gen_ps.log', |
26
|
|
|
|
|
|
|
dir => undef, |
27
|
|
|
|
|
|
|
logfh => undef, |
28
|
|
|
|
|
|
|
dupefh => undef, |
29
|
|
|
|
|
|
|
verbose => 0, |
30
|
|
|
|
|
|
|
@_ |
31
|
|
|
|
|
|
|
}; |
32
|
0
|
0
|
0
|
|
|
|
if (!(defined $self->{dir} && -d $self->{dir})) { |
33
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException 'TeX::AutoTeX::Log::new requires a directory (dir) option to write the log to' |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
bless $self, $class; |
36
|
0
|
0
|
|
|
|
|
$self->{dupefh}->autoflush(1) if $self->{dupefh}; |
37
|
0
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub open_logfile { |
41
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
42
|
0
|
0
|
|
|
|
|
if (!$self->{logfile}) { |
43
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException q{Can't open log file without a name.}; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
0
|
|
|
|
|
open($self->{logfh}, '>', "$self->{dir}/$self->{logfile}") |
46
|
|
|
|
|
|
|
|| throw TeX::AutoTeX::FatalException "Could not open log file '$self->{logfile}' for writing."; |
47
|
0
|
|
|
|
|
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub close_logfile { |
51
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
52
|
0
|
0
|
|
|
|
|
if ($self->{logfh}) { |
53
|
0
|
0
|
|
|
|
|
close $self->{logfh} || carp q{couldn't close logfile}; |
54
|
0
|
|
|
|
|
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub error { |
60
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
61
|
0
|
|
|
|
|
|
$msg =~ s/\n\s*$//; |
62
|
0
|
|
|
|
|
|
$self->__logit('error', "$msg\n*** AutoTeX ABORTING ***\n"); |
63
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException $msg; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub verbose { |
67
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
68
|
0
|
0
|
|
|
|
|
$self->__logit('verbose', $msg) if $self->{verbose}; |
69
|
0
|
|
|
|
|
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub __logit { |
73
|
0
|
|
|
0
|
|
|
my ($self, $level, $msg) = @_; |
74
|
0
|
|
|
|
|
|
$msg = "[$level]: $msg\n"; |
75
|
0
|
0
|
|
|
|
|
if ($self->{logfh}) { |
76
|
0
|
|
|
|
|
|
print {$self->{logfh}} $msg; |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
|
if ($self->{dupefh}) { |
79
|
0
|
|
|
|
|
|
print {$self->{dupefh}} $msg; |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub to_stringref { |
85
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
seek $self->{logfh}, 0, 1; # flush buffered log messages |
87
|
0
|
0
|
|
|
|
|
if (open my $LOG, '<', "$self->{dir}/$self->{logfile}") { |
88
|
0
|
|
|
|
|
|
my $logcontent; |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
|
|
|
local $/ = undef; |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$logcontent = <$LOG>; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
0
|
|
|
|
|
close $LOG || carp q{couldn't close logfile}; |
94
|
0
|
|
|
|
|
|
return \$logcontent; |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
carp q{can't open logfile}; |
97
|
0
|
|
|
|
|
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |