line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::Log::Json; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
611
|
use XAS::Factory; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use XAS::Class |
8
|
1
|
|
|
|
|
4
|
debug => 0, |
9
|
|
|
|
|
|
|
version => $VERSION, |
10
|
|
|
|
|
|
|
base => 'XAS::Base', |
11
|
|
|
|
|
|
|
utils => ':validation level2syslog', |
12
|
|
|
|
|
|
|
codec => 'JSON', |
13
|
|
|
|
|
|
|
accessors => 'spooler', |
14
|
|
|
|
|
|
|
constants => 'HASHREF', |
15
|
|
|
|
|
|
|
filesystem => 'Dir', |
16
|
1
|
|
|
1
|
|
82
|
; |
|
1
|
|
|
|
|
1
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# note to self: Don't but $self->log->debug() statements in here |
19
|
|
|
|
|
|
|
# it will produce a nice race condition. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
# Public Methods |
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub output { |
26
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
27
|
0
|
|
|
|
|
|
my ($args) = validate_params(\@_, [ |
28
|
|
|
|
|
|
|
{ type => HASHREF } |
29
|
|
|
|
|
|
|
]); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $message = sprintf('[%s] %-5s - %s', |
32
|
|
|
|
|
|
|
$args->{'datetime'}->strftime('%Y-%m-%d %H:%M:%S'), |
33
|
|
|
|
|
|
|
uc($args->{'priority'}), |
34
|
0
|
|
|
|
|
|
$args->{'message'} |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# create a logstash "json_event" |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $data = { |
40
|
|
|
|
|
|
|
'@timestamp' => $args->{'datetime'}->strftime('%Y-%m-%dT%H:%M:%S.%3N%z'), |
41
|
|
|
|
|
|
|
'@version' => '1', |
42
|
|
|
|
|
|
|
'@message' => $message, |
43
|
|
|
|
|
|
|
type => 'xas-logs', |
44
|
|
|
|
|
|
|
message => $args->{'message'}, |
45
|
|
|
|
|
|
|
hostname => $args->{'hostname'}, |
46
|
|
|
|
|
|
|
priority => level2syslog($args->{'priority'}), |
47
|
|
|
|
|
|
|
facility => $args->{'facility'}, |
48
|
|
|
|
|
|
|
process => $args->{'process'}, |
49
|
0
|
|
|
|
|
|
pid => $args->{'pid'} |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $json = encode($data); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# write the spool file |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->spooler->write($json); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
# Private Methods |
62
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub init { |
65
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->{'spooler'} = XAS::Factory->module('spool', { |
70
|
|
|
|
|
|
|
-directory => Dir($self->env->spool, 'logs'), |
71
|
|
|
|
|
|
|
-lock => Dir($self->env->spool, 'logs', 'locked')->path, |
72
|
|
|
|
|
|
|
}); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $self; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |