line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eidolon::Driver::Log::Basic; |
2
|
|
|
|
|
|
|
# ============================================================================== |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Eidolon |
5
|
|
|
|
|
|
|
# Copyright (c) 2009, Atma 7 |
6
|
|
|
|
|
|
|
# --- |
7
|
|
|
|
|
|
|
# Eidolon/Driver/Log/Basic.pm - basic log driver |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# ============================================================================== |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
103229
|
use base qw/Eidolon::Driver::Log/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
108
|
|
12
|
1
|
|
|
1
|
|
1269
|
use POSIX "strftime"; |
|
1
|
|
|
|
|
27448
|
|
|
1
|
|
|
|
|
11
|
|
13
|
1
|
|
|
1
|
|
1330
|
use Fcntl ":flock"; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
156
|
|
14
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
15
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
562
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = "0.01"; # 2008-09-26 23:21:32 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
20
|
|
|
|
|
|
|
# \% new($logs_dir, $file) |
21
|
|
|
|
|
|
|
# constructor |
22
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
23
|
|
|
|
|
|
|
sub new |
24
|
|
|
|
|
|
|
{ |
25
|
0
|
|
|
0
|
1
|
|
my ($class, $dir, $file, $self); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
($class, $dir, $file) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self = $class->SUPER::new; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# class attributes |
32
|
0
|
|
|
|
|
|
$self->{"dir"} = $dir; |
33
|
0
|
|
0
|
|
|
|
$self->{"file"} = $file || "system.log"; |
34
|
0
|
|
|
|
|
|
$self->{"handle"} = undef; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# check if log directory exists |
37
|
0
|
0
|
|
|
|
|
throw DriverError::Log::Directory($self->{"dir"}) if (!-d $self->{"dir"}); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
43
|
|
|
|
|
|
|
# open() |
44
|
|
|
|
|
|
|
# open log |
45
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
46
|
|
|
|
|
|
|
sub open |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
$self->close if ($self->{"handle"}); |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
open $self->{"handle"}, ">>$self->{'dir'}$self->{'file'}" or |
53
|
|
|
|
|
|
|
throw DriverError::Log::Open($self->{"dir"}.$self->{"file"}); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
flock $self->{"handle"}, LOCK_EX; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
59
|
|
|
|
|
|
|
# close() |
60
|
|
|
|
|
|
|
# close log |
61
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
62
|
|
|
|
|
|
|
sub close |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ($self->{"handle"}) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
|
flock $self->{"handle"}, LOCK_UN; |
69
|
0
|
|
|
|
|
|
close $self->{"handle"}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
74
|
|
|
|
|
|
|
# _write($level, $msg) |
75
|
|
|
|
|
|
|
# write log |
76
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
77
|
|
|
|
|
|
|
sub _write |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
|
|
my ($self, $level, $msg, $r, $fh); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
($self, $level, $msg) = @_; |
82
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->get_instance; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->open; |
85
|
0
|
|
|
|
|
|
$fh = $self->{"handle"}; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
printf $fh |
88
|
|
|
|
|
|
|
( |
89
|
|
|
|
|
|
|
"[ %s ]\t%s\t%s\t%s\n", |
90
|
|
|
|
|
|
|
strftime("%Y-%m-%d %H:%M:%S", localtime), |
91
|
|
|
|
|
|
|
$r->cgi->get_query || "/", |
92
|
|
|
|
|
|
|
$level, |
93
|
|
|
|
|
|
|
$msg ? $msg : "-" |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$self->close; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
100
|
|
|
|
|
|
|
# notice($msg) |
101
|
|
|
|
|
|
|
# notice |
102
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
103
|
|
|
|
|
|
|
sub notice |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$self->_write("notice", $msg); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
111
|
|
|
|
|
|
|
# warning($msg) |
112
|
|
|
|
|
|
|
# warning |
113
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
114
|
|
|
|
|
|
|
sub warning |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$self->_write("warning", $msg); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
122
|
|
|
|
|
|
|
# error($msg) |
123
|
|
|
|
|
|
|
# error |
124
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
125
|
|
|
|
|
|
|
sub error |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
|
|
0
|
1
|
|
my ($self, $msg) = @_; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$self->_write("error", $msg); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |