line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::Log::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XAS::Class |
6
|
1
|
|
|
|
|
5
|
debug => 0, |
7
|
|
|
|
|
|
|
version => $VERSION, |
8
|
|
|
|
|
|
|
base => 'XAS::Base', |
9
|
|
|
|
|
|
|
utils => ':validation dotid', |
10
|
|
|
|
|
|
|
constants => 'HASHREF', |
11
|
1
|
|
|
1
|
|
596
|
; |
|
1
|
|
|
|
|
2
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
# Public Methods |
15
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub output { |
18
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
19
|
0
|
|
|
|
|
|
my ($args) = validate_params(\@_, [ |
20
|
|
|
|
|
|
|
{ type => HASHREF } |
21
|
|
|
|
|
|
|
]); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->env->log_file->append( |
24
|
|
|
|
|
|
|
sprintf("[%s] %-5s - %s\n", |
25
|
|
|
|
|
|
|
$args->{'datetime'}->strftime('%Y-%m-%d %H:%M:%S'), |
26
|
|
|
|
|
|
|
uc($args->{'priority'}), |
27
|
0
|
|
|
|
|
|
$args->{'message'} |
28
|
|
|
|
|
|
|
)); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
# Private Methods |
34
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init { |
37
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# check to see if the file exists, otherwise create it |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
unless ($self->env->log_file->exists) { |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if (my $fh = $self->env->log_file->open('>')) { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$fh->close; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} else { |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->throw_msg( |
52
|
|
|
|
|
|
|
dotid($self->class) . '.init.creatfile', |
53
|
|
|
|
|
|
|
'file_create', |
54
|
|
|
|
|
|
|
$self->env->log_file->path |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Change the file permissions to rw-rw-r, skip this on Windows |
62
|
|
|
|
|
|
|
# as this will create a read only file. |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ($^O ne "MSWin32") { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my ($cnt, $mode, $permissions); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# set file permissions |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$mode = ($self->env->log_file->stat)[2]; |
71
|
0
|
|
|
|
|
|
$permissions = sprintf("%04o", $mode & 07777); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($permissions ne "0664") { |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$cnt = chmod(0664, $self->env->log_file->path); |
76
|
0
|
0
|
|
|
|
|
$self->throw_msg( |
77
|
|
|
|
|
|
|
dotid($self->class) . '.init.invperms', |
78
|
|
|
|
|
|
|
'file_perms', |
79
|
|
|
|
|
|
|
$self->env->log_file->path) if ($cnt < 1); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |