← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:14 2014

Filename/usr/local/lib/site_perl/Log/Writer/Syslog.pm
StatementsExecuted 28 statements in 934µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.68ms6.44msLog::Writer::Syslog::::BEGIN@70Log::Writer::Syslog::BEGIN@70
11112µs12µsLog::Writer::Syslog::::BEGIN@82Log::Writer::Syslog::BEGIN@82
11111µs14µsLog::Writer::Syslog::::BEGIN@2Log::Writer::Syslog::BEGIN@2
1118µs38µsLog::Writer::Syslog::::BEGIN@113Log::Writer::Syslog::BEGIN@113
1117µs56µsLog::Writer::Syslog::::BEGIN@83Log::Writer::Syslog::BEGIN@83
1117µs30µsLog::Writer::Syslog::::BEGIN@68Log::Writer::Syslog::BEGIN@68
1117µs42µsLog::Writer::Syslog::::BEGIN@69Log::Writer::Syslog::BEGIN@69
1117µs43µsLog::Writer::Syslog::::BEGIN@67Log::Writer::Syslog::BEGIN@67
1116µs6µsLog::Writer::Syslog::::BEGIN@78Log::Writer::Syslog::BEGIN@78
1116µs11µsLog::Writer::Syslog::::BEGIN@3Log::Writer::Syslog::BEGIN@3
1116µs32µsLog::Writer::Syslog::::BEGIN@114Log::Writer::Syslog::BEGIN@114
1115µs5µsLog::Writer::Syslog::::BEGIN@79Log::Writer::Syslog::BEGIN@79
1113µs3µsLog::Writer::Syslog::::ENDLog::Writer::Syslog::END
0000s0sLog::Writer::Syslog::::DESTROYLog::Writer::Syslog::DESTROY
0000s0sLog::Writer::Syslog::::_format_messageLog::Writer::Syslog::_format_message
0000s0sLog::Writer::Syslog::::_get_possible_flagsLog::Writer::Syslog::_get_possible_flags
0000s0sLog::Writer::Syslog::::_initLog::Writer::Syslog::_init
0000s0sLog::Writer::Syslog::::writeLog::Writer::Syslog::write
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Log::Writer::Syslog;
2221µs217µs
# spent 14µs (11+3) within Log::Writer::Syslog::BEGIN@2 which was called: # once (11µs+3µs) by Log::Loger::BEGIN@133 at line 2
use strict;
# spent 14µs making 1 call to Log::Writer::Syslog::BEGIN@2 # spent 3µs making 1 call to strict::import
3253µs216µs
# spent 11µs (6+5) within Log::Writer::Syslog::BEGIN@3 which was called: # once (6µs+5µs) by Log::Loger::BEGIN@133 at line 3
use warnings;
# spent 11µs making 1 call to Log::Writer::Syslog::BEGIN@3 # spent 5µs making 1 call to warnings::import
4
5#*******************************************************************************
6#
7# DOCUMENTATION SECTION
8#
9#*******************************************************************************
10
11=head1 NAME
12
13Log::Writer::Syslog - Log writer capable of logging messages to syslog
14
15=head1 SYNOPSIS
16
17 use Log::Writer::Syslog;
18
19
20=head1 DESCRIPTION
21
22This writer writes given messages to the given IO::Handle.
23
24=head1 USAGE
25
26=head1 BUGS
27
28=head1 FLAGS
29
30 rep r REPLACE_SOURCE
31 ser s SERIALIZE
32 tra t TRACEBACK
33
34=head1 AUTHOR
35
36Jan Mach
37Cesnet, z.s.p.o
38jan.mach@cesnet.cz
39http://www.cesnet.cz
40
41=head1 COPYRIGHT
42
43This program is free software; you can redistribute
44it and/or modify it under the same terms as Perl itself.
45
46The full text of the license can be found in the
47LICENSE file included with this module.
48
49
50=head1 SEE ALSO
51
52perl(1).
53
54=head1 FUNCTION REFERENCE
55
56=over 4
57
58=cut
59
60#*******************************************************************************
61#
62# INITIALIZATION AND CLEANUP SECTION
63#
64#*******************************************************************************
65
66#-- Perl core modules ---------------------------------------------------------#
67224µs280µs
# spent 43µs (7+37) within Log::Writer::Syslog::BEGIN@67 which was called: # once (7µs+37µs) by Log::Loger::BEGIN@133 at line 67
use Carp;
# spent 43µs making 1 call to Log::Writer::Syslog::BEGIN@67 # spent 37µs making 1 call to Exporter::import
68222µs252µs
# spent 30µs (7+22) within Log::Writer::Syslog::BEGIN@68 which was called: # once (7µs+22µs) by Log::Loger::BEGIN@133 at line 68
use Scalar::Util 'blessed';
# spent 30µs making 1 call to Log::Writer::Syslog::BEGIN@68 # spent 22µs making 1 call to Exporter::import
69225µs276µs
# spent 42µs (7+35) within Log::Writer::Syslog::BEGIN@69 which was called: # once (7µs+35µs) by Log::Loger::BEGIN@133 at line 69
use File::Basename;
# spent 42µs making 1 call to Log::Writer::Syslog::BEGIN@69 # spent 35µs making 1 call to Exporter::import
702105µs26.86ms
# spent 6.44ms (3.68+2.76) within Log::Writer::Syslog::BEGIN@70 which was called: # once (3.68ms+2.76ms) by Log::Loger::BEGIN@133 at line 70
use Sys::Syslog qw(:standard :macros setlogsock);
# spent 6.44ms making 1 call to Log::Writer::Syslog::BEGIN@70 # spent 424µs making 1 call to Exporter::import
71
72#use Data::Dumper; #-+-> DEVEL ONLY <-+-#
73#use Smart::Comments; #-+-> DEVEL ONLY <-+-#
74
75#-- Perl CPAN modules ---------------------------------------------------------#
76
77#-- Custom application modules ------------------------------------------------#
78226µs16µs
# spent 6µs within Log::Writer::Syslog::BEGIN@78 which was called: # once (6µs+0s) by Log::Loger::BEGIN@133 at line 78
use Log::Core::Essentials;
# spent 6µs making 1 call to Log::Writer::Syslog::BEGIN@78
79229µs15µs
# spent 5µs within Log::Writer::Syslog::BEGIN@79 which was called: # once (5µs+0s) by Log::Loger::BEGIN@133 at line 79
use Log::Writer::Module;
# spent 5µs making 1 call to Log::Writer::Syslog::BEGIN@79
80
81#-- Module initializations ----------------------------------------------------#
82
# spent 12µs within Log::Writer::Syslog::BEGIN@82 which was called: # once (12µs+0s) by Log::Loger::BEGIN@133 at line 99
BEGIN {
832119µs2104µs
# spent 56µs (7+48) within Log::Writer::Syslog::BEGIN@83 which was called: # once (7µs+48µs) by Log::Loger::BEGIN@133 at line 83
use vars qw($VERSION $DEVEL @ISA %SEV2PRIO);
# spent 56µs making 1 call to Log::Writer::Syslog::BEGIN@83 # spent 48µs making 1 call to vars::import
84412µs $VERSION = '0.01';
85 $DEVEL = 0;
86 @ISA = ('Log::Writer::Module');
87
88 %SEV2PRIO = (
89 Log::Core::Essentials::EMAIL_STR() => LOG_EMERG, # special internal severity
90 Log::Core::Essentials::EMERG_STR() => LOG_EMERG, # system is unusable
91 Log::Core::Essentials::ALERT_STR() => LOG_ALERT, # action must be taken immediately
92 Log::Core::Essentials::CRIT_STR() => LOG_CRIT, # critical conditions
93 Log::Core::Essentials::ERROR_STR() => LOG_ERR, # error conditions
94 Log::Core::Essentials::WARNING_STR() => LOG_WARNING, # warning conditions
95 Log::Core::Essentials::NOTICE_STR() => LOG_NOTICE, # normal, but significant, condition
96 Log::Core::Essentials::INFO_STR() => LOG_INFO, # informational message
97 Log::Core::Essentials::DEBUG_STR() => LOG_DEBUG, # debug-level message
98 );
99139µs112µs}
# spent 12µs making 1 call to Log::Writer::Syslog::BEGIN@82
100
101#-- Module clean-up code (global destructor) ----------------------------------#
10212µs
# spent 3µs within Log::Writer::Syslog::END which was called: # once (3µs+0s) by main::RUNTIME at line 0 of mentat.storage.mongo.pl
END {
103
104}
105
106#*******************************************************************************
107#
108# CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION
109#
110#*******************************************************************************
111
112#-- Constants -----------------------------------------------------------------#
113227µs268µs
# spent 38µs (8+30) within Log::Writer::Syslog::BEGIN@113 which was called: # once (8µs+30µs) by Log::Loger::BEGIN@133 at line 113
use constant FLAG_REPLACE => 'REPLACE';
# spent 38µs making 1 call to Log::Writer::Syslog::BEGIN@113 # spent 30µs making 1 call to constant::import
1142428µs258µs
# spent 32µs (6+26) within Log::Writer::Syslog::BEGIN@114 which was called: # once (6µs+26µs) by Log::Loger::BEGIN@133 at line 114
use constant FLAG_TRACEBACK => 'TRACEBACK';
# spent 32µs making 1 call to Log::Writer::Syslog::BEGIN@114 # spent 26µs making 1 call to constant::import
115
116#-- Static public class variables (our) ---------------------------------------#
117
118#-- Static protected class variables (my) -------------------------------------#
119
120#*******************************************************************************
121#
122# IMPLEMENTATION SECTION
123#
124#*******************************************************************************
125
126=item write($$$) [PUBLIC]
127
128 Usage : $writer->write($source, $severity, $message);
129 Purpose : Write given message to the destination
130 Arguments : STRING $source - Name of the source of the message
131 ENUM $severity - Severity in integer or string format (see Log::Core::Essentials for permited values)
132 STRING $message - Log message
133 Returns : $self
134 Throws : Croaks, if not implemented in descendant classes
135 Comments : ABSTRACT method, must be implemented in descendant classes
136 See Also : Log::Core::Essentials module for permited severity values
137
138=cut
139
140sub write($$$)
141{
142 my $self = shift;
143 croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self);
144 my ($source, $severity, $message) = @_;
145 croak ((caller(0))[3] . ": invalid arguments") unless (defined($source) and defined($severity) and defined($message));
146 croak ((caller(0))[3] . ": invalid severity value '$severity'") unless exists $SEV2PRIO{uc($severity)};
147
148 syslog($SEV2PRIO{uc($severity)}, $self->_format_message($source, $severity, $message));
149
150 return $self;
151}
152
153=item DESTROY [PUBLIC]
154
155 Usage : Instance destructor
156 Purpose : Close opened log file handle
157 Returns : Nothing
158 Arguments : None
159 Throws : Nothing
160
161=cut
162
163sub DESTROY {
164 my $self = shift;
165 croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self);
166
167 closelog();
168}
169
170#-------------------------------------------------------------------------------
171# Private interface
172#-------------------------------------------------------------------------------
173
174# _init [PROTECTED]
175#
176# Usage : return $self->_init(@_);
177# Purpose : Initialize the new Log::Writer::String instance
178# Arguments : SCALAR $buffer - string buffer variable
179# (for other _init arguments see Log::Writer::Handle class)
180# Returns : Log::Writer::Module reference
181# Throws : Croaks, if invoked on class, or if given invalid arguments
182# See also : Log::Writer::Handle module
183
184sub _init
185{
186 my $self = shift;
187 croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self);
188 my ($facility, $flags) = @_;
189 $facility = LOG_LOCAL7 unless $facility;
190
191 setlogsock('unix');
192 openlog(basename($0),'pid',$facility);
193
194 $self->_setup_flags($flags);
195
196 return $self;
197}
198
199# _get_possible_flags() [PROTECTED]
200#
201# Usage : my $flags = $self->_get_possible_flags();
202# Purpose : Get hash structure describing all possible flags
203# Arguments : None
204# Returns : HASH REFERENCE $flags
205# Throws : Croaks, if invoked on class
206
207sub _get_possible_flags()
208{
209 my $self = shift;
210 croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self);
211
212 return {
213 'r' => FLAG_REPLACE(),
214 'rep' => FLAG_REPLACE(),
215 'replace' => FLAG_REPLACE(),
216 't' => FLAG_TRACEBACK(),
217 'tra' => FLAG_TRACEBACK(),
218 'traceback' => FLAG_TRACEBACK(),
219 };
220}
221
222# _format_message($$$) [PROTECTED]
223#
224# Usage : my $message = $self->_format_message($source, $severity, $message)
225# Purpose : Format log message from the given source, severity and message body
226# Arguments : STRING $source - Name of the source of the message
227# ENUM $severity - Severity in integer or string format (see Log::Core::Essentials for permited values)
228# STRING $message - Message
229# Returns : STRING formatted message
230# Throws : Croaks, if invoked on class
231
232sub _format_message($$$)
233{
234 my $self = shift;
235 croak ((caller(0))[3] . ": instance method invoked on class") unless blessed($self);
236 my ($source, $severity, $message) = @_;
237
238 $source = basename($0) if ($self->_flag(FLAG_REPLACE()));
239
240 return "$source: $message\n" unless $self->_flag(FLAG_TRACEBACK());
241 return "$source: $message\n Backtrace:\n * " . join("\n * ", $self->_traceback()) . "\n";
242}
243
244=pod
245
246=back
247
248=cut
249
25012µs1;