line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::FileSimple; |
2
|
|
|
|
|
|
|
# questo componente utilizzando un file di log puņ essere usato per fare |
3
|
|
|
|
|
|
|
# il debug di componenti |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
22346
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
26
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
98
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
710
|
use FileHandle; |
|
1
|
|
|
|
|
12561
|
|
|
1
|
|
|
|
|
7
|
|
12
|
1
|
|
|
1
|
|
1613
|
use Data::Dumper; |
|
1
|
|
|
|
|
10448
|
|
|
1
|
|
|
|
|
573
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$Log::FileSimple::VERSION = '0.02'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Fields that can be set in new method, with defaults |
18
|
|
|
|
|
|
|
my %fields =( |
19
|
|
|
|
|
|
|
file => '/tmp/log.log', |
20
|
|
|
|
|
|
|
name => undef, |
21
|
|
|
|
|
|
|
mask => 0xFFFF, |
22
|
|
|
|
|
|
|
autoflush => 0, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new |
26
|
|
|
|
|
|
|
{ |
27
|
1
|
|
|
1
|
0
|
19
|
my ($proto,%options) = @_; |
28
|
1
|
|
33
|
|
|
8
|
my $class = ref($proto) || $proto; |
29
|
1
|
|
|
|
|
5
|
my $self = { |
30
|
|
|
|
|
|
|
%fields}; |
31
|
1
|
|
|
|
|
8
|
while (my ($key,$value) = each(%options)) { |
32
|
4
|
50
|
|
|
|
8
|
if (exists($fields{$key})) { |
33
|
4
|
50
|
|
|
|
16
|
$self->{$key} = $value if (defined $value); |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
|
|
|
|
0
|
die ref($class) . "::new: invalid option '$key'\n"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
1
|
|
|
|
|
3
|
foreach (keys(%fields)) { |
39
|
4
|
50
|
|
|
|
11
|
die ref($class) . "::new: must specify value for $_" |
40
|
|
|
|
|
|
|
if (!defined $self->{$_}); |
41
|
|
|
|
|
|
|
} |
42
|
1
|
50
|
|
|
|
5
|
$self->{mask} = 0xFFFF if ($self->{mask} == -1); |
43
|
1
|
|
|
|
|
2
|
bless $self, $class; |
44
|
1
|
|
|
|
|
5
|
$self->_init; |
45
|
1
|
|
|
|
|
4
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _init { |
49
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
50
|
1
|
|
|
|
|
14
|
$self->{fh} = new FileHandle ">>$self->{file}"; |
51
|
1
|
|
|
|
|
183
|
$self->{fh}->autoflush($self->{autoflush}); |
52
|
1
|
50
|
|
|
|
50
|
die "Unable to write to $self->{file}" if (!defined $self->{fh}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub DESTROY { |
56
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
57
|
1
|
|
|
|
|
6
|
$self->{fh}->close; |
58
|
1
|
|
|
|
|
190
|
undef $self->{fh}; |
59
|
|
|
|
|
|
|
# Enter here your code |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub log { |
63
|
6
|
|
|
6
|
0
|
1085
|
my $self = shift; |
64
|
6
|
|
|
|
|
19
|
my %log_data = @_; |
65
|
|
|
|
|
|
|
|
66
|
6
|
100
|
|
|
|
18
|
$log_data{'id'} = $self->{mask} |
67
|
|
|
|
|
|
|
if (!exists $log_data{'id'}); |
68
|
|
|
|
|
|
|
#$self->{fh}->print("Data :" . $log_data{'id'} . "-" . |
69
|
|
|
|
|
|
|
# $self->{mask} . "-" . ($log_data{'id'} & $self->{mask}) ."\n"); |
70
|
6
|
100
|
|
|
|
19
|
return if (($log_data{'id'} & $self->{mask}) == 0); |
71
|
5
|
|
|
|
|
246
|
my $timestamp = localtime; |
72
|
5
|
|
|
|
|
11
|
my $sep = '-' x 80; |
73
|
5
|
50
|
|
|
|
15
|
my $log_data = $log_data{'message'} . "\n" |
74
|
|
|
|
|
|
|
if (exists $log_data{'message'}); |
75
|
|
|
|
|
|
|
|
76
|
5
|
100
|
|
|
|
11
|
if (exists $log_data{'objects'}) { |
77
|
2
|
|
|
|
|
3
|
foreach (@{$log_data{'objects'}}) { |
|
2
|
|
|
|
|
5
|
|
78
|
3
|
|
|
|
|
80
|
$log_data .= Data::Dumper::Dumper($_) . "\n"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
5
|
|
|
|
|
176
|
my $print_data =<
|
83
|
|
|
|
|
|
|
[$timestamp] -> $self->{name} |
84
|
|
|
|
|
|
|
$log_data |
85
|
|
|
|
|
|
|
$sep |
86
|
|
|
|
|
|
|
EOF |
87
|
5
|
|
|
|
|
19
|
$self->{fh}->print($print_data); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
2
|
100
|
|
2
|
0
|
377
|
sub mask { my $s = shift; if (@_) { $s->{mask} = shift; } return $s->{mask}; } |
|
2
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
6
|
|
91
|
|
|
|
|
|
|
|