line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Plugin::Log::Syslog; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Syslog.pm 217 2007-11-07 00:49:15Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
2
|
|
|
2
|
|
29062
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
72
|
|
8
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
9
|
2
|
|
|
2
|
|
15237
|
use Sys::Syslog qw/:DEFAULT setlogsock/; |
|
2
|
|
|
|
|
51478
|
|
|
2
|
|
|
|
|
1079
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Egg::Plugin::Log::Syslog - Plugin for Sys::Syslog. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Egg qw/ Log::Syslog /; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# It writes it in the log. |
22
|
|
|
|
|
|
|
$e->slog(' log message '); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
It is a plugin to use Log::Syslog module. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 CONFIGRATION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
First of all, please set Syslog. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# * It is a setting example for Linux. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
% vi /etc/syslog.conf |
35
|
|
|
|
|
|
|
local3.* /var/log/myapp_log |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
% /sbin/service syslog restart |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Whether the setting became effective is confirmed. |
40
|
|
|
|
|
|
|
% logger -p local3.debug ' TEST OK!! ' |
41
|
|
|
|
|
|
|
% tail /var/log/myapp_log |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
After the above-mentioned is set, the setting of plugin_syslog is added to the |
44
|
|
|
|
|
|
|
configuration of the project. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
plugin_syslog => { |
47
|
|
|
|
|
|
|
facility => 'local3', |
48
|
|
|
|
|
|
|
handle => 'MYAPPLOG', |
49
|
|
|
|
|
|
|
unix_socket => 1, |
50
|
|
|
|
|
|
|
level => 'debug', |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
It is as follows of each item. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over 4 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item * facility |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Name of log facility set to 'syslog.conf'. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item * handle |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Electronic alias when log is opened. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Default is a project name. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * unix_socket |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
setlogsock('unix') is issued when making it to true. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
* There seems to be a thing that cannot be written well if this is not done |
72
|
|
|
|
|
|
|
according to the environment. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Default is false. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item * level |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
It is a log level. It always writes it at the log level set by this. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
And, it might be good to put the setting of the following rotations on '/etc/logrotate.d'. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
/var/log/myapp_log { |
85
|
|
|
|
|
|
|
weekly |
86
|
|
|
|
|
|
|
missingok |
87
|
|
|
|
|
|
|
notifempty |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
* I think that it should reactivate the WEB server and the database server after |
91
|
|
|
|
|
|
|
it rotates. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 slog ([LOG_MESSAGE]) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
LOG_MESSAGE is written the log. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$e->slog(' myapp memo. '); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _setup { |
104
|
0
|
|
|
0
|
|
|
my($e)= @_; |
105
|
0
|
|
0
|
|
|
|
my $conf= $e->config->{plugin_syslog} ||= {}; |
106
|
0
|
0
|
|
|
|
|
$conf->{facility} || die q{ I want setup 'facility'. }; |
107
|
0
|
|
0
|
|
|
|
$conf->{handle} ||= $e->namespace; |
108
|
0
|
|
|
|
|
|
$conf->{handle}=~s{\:+} [_]g; |
109
|
0
|
0
|
|
|
|
|
setlogsock('unix') if $conf->{unix_socket}; |
110
|
0
|
|
|
|
|
|
openlog($conf->{handle}, 'cons,pid', $conf->{facility}); |
111
|
0
|
|
0
|
|
|
|
my $level= $conf->{level} || 'debug'; |
112
|
|
|
|
|
|
|
*slog= sub { |
113
|
0
|
|
|
0
|
|
|
my $egg= shift; |
114
|
0
|
|
0
|
|
|
|
syslog($level, ($_[0] || 'Internal error.')); |
115
|
0
|
|
|
|
|
|
}; |
116
|
0
|
|
|
|
|
|
$e->slog(">>> '$e->{namespace}' Logging start."); |
117
|
0
|
|
|
|
|
|
$e->next::method; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
sub DESTROY { |
120
|
0
|
|
|
0
|
|
|
closelog(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L<Sys::Syslog>, |
130
|
|
|
|
|
|
|
L<Egg::Release>, |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright (C) 2007 by Bee Flag, Corp. E<lt>http://egg.bomcity.com/E<gt>, All Rights Reserved. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
141
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
142
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|