Profile of Log/Log4perl/JavaMap.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:35 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Log/Log4perl/JavaMap.pm
Statements | Executed 12 statements in 291µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 15µs | 71µs | Log::Log4perl::JavaMap::::BEGIN@3Log::Log4perl::JavaMap::BEGIN@3
1 | 1 | 1 | 7µs | 9µs | Log::Log4perl::JavaMap::::BEGIN@4Log::Log4perl::JavaMap::BEGIN@4
1 | 1 | 1 | 7µs | 33µs | Log::Log4perl::JavaMap::::BEGIN@6Log::Log4perl::JavaMap::BEGIN@6
0 | 0 | 0 | 0s | 0s | Log::Log4perl::JavaMap::::getLog::Log4perl::JavaMap::get
0 | 0 | 0 | 0s | 0s | Log::Log4perl::JavaMap::::translateLog::Log4perl::JavaMap::translate

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Log::Log4perl::JavaMap;
2 |  |  |  |  |
3 | 3 | 22µs | 2 | 127µs | # spent 71µs (15+56) within Log::Log4perl::JavaMap::BEGIN@3 which was called: # once (15µs+56µs) by Log::Log4perl::Config::BEGIN@11 at line 3 use Carp; # spent 71µs making 1 call to Log::Log4perl::JavaMap::BEGIN@3 # spent 56µs making 1 call to Exporter::import
4 | 3 | 19µs | 2 | 10µs | # spent 9µs (7+2) within Log::Log4perl::JavaMap::BEGIN@4 which was called: # once (7µs+2µs) by Log::Log4perl::Config::BEGIN@11 at line 4 use strict; # spent 9µs making 1 call to Log::Log4perl::JavaMap::BEGIN@4 # spent 2µs making 1 call to strict::import
5 |  |  |  |  |
6 | 3 | 242µs | 2 | 60µs | # spent 33µs (7+27) within Log::Log4perl::JavaMap::BEGIN@6 which was called: # once (7µs+27µs) by Log::Log4perl::Config::BEGIN@11 at line 6 use constant _INTERNAL_DEBUG => 0; # spent 33µs making 1 call to Log::Log4perl::JavaMap::BEGIN@6 # spent 27µs making 1 call to constant::import
7 |  |  |  |  |
8 | 1 | 5µs |  |  | our %translate = (
9 |  |  |  |  | 'org.apache.log4j.ConsoleAppender' =>
10 |  |  |  |  | 'Log::Log4perl::JavaMap::ConsoleAppender',
11 |  |  |  |  | 'org.apache.log4j.FileAppender' =>
12 |  |  |  |  | 'Log::Log4perl::JavaMap::FileAppender',
13 |  |  |  |  | 'org.apache.log4j.RollingFileAppender' =>
14 |  |  |  |  | 'Log::Log4perl::JavaMap::RollingFileAppender',
15 |  |  |  |  | 'org.apache.log4j.TestBuffer' =>
16 |  |  |  |  | 'Log::Log4perl::JavaMap::TestBuffer',
17 |  |  |  |  | 'org.apache.log4j.jdbc.JDBCAppender' =>
18 |  |  |  |  | 'Log::Log4perl::JavaMap::JDBCAppender',
19 |  |  |  |  | 'org.apache.log4j.SyslogAppender' =>
20 |  |  |  |  | 'Log::Log4perl::JavaMap::SyslogAppender',
21 |  |  |  |  | 'org.apache.log4j.NTEventLogAppender' =>
22 |  |  |  |  | 'Log::Log4perl::JavaMap::NTEventLogAppender',
23 |  |  |  |  | );
24 |  |  |  |  |
25 | 1 | 200ns |  |  | our %user_defined;
26 |  |  |  |  |
27 |  |  |  |  | sub get {
28 |  |  |  |  | my ($appender_name, $appender_data) = @_;
29 |  |  |  |  |
30 |  |  |  |  | print "Trying to map $appender_name\n" if _INTERNAL_DEBUG;
31 |  |  |  |  |
32 |  |  |  |  | $appender_data->{value} ||
33 |  |  |  |  | die "ERROR: you didn't tell me how to implement your appender " .
34 |  |  |  |  | "'$appender_name'";
35 |  |  |  |  |
36 |  |  |  |  | my $perl_class = $translate{$appender_data->{value}} ||
37 |  |  |  |  | $user_defined{$appender_data->{value}} ||
38 |  |  |  |  | die "ERROR: I don't know how to make a '$appender_data->{value}' " .
39 |  |  |  |  | "to implement your appender '$appender_name', that's not a " .
40 |  |  |  |  | "supported class\n";
41 |  |  |  |  | eval {
42 |  |  |  |  | eval "require $perl_class"; #see 'perldoc -f require' for why two evals
43 |  |  |  |  | die $@ if $@;
44 |  |  |  |  | };
45 |  |  |  |  | $@ and die "ERROR: trying to set appender for $appender_name to " .
46 |  |  |  |  | "$appender_data->{value} using $perl_class failed\n$@ \n";
47 |  |  |  |  |
48 |  |  |  |  | my $app = $perl_class->new($appender_name, $appender_data);
49 |  |  |  |  | return $app;
50 |  |  |  |  | }
51 |  |  |  |  |
52 |  |  |  |  | #an external api to the two hashes
53 |  |  |  |  | sub translate {
54 |  |  |  |  | my $java_class = shift;
55 |  |  |  |  |
56 |  |  |  |  | return $translate{$java_class} ||
57 |  |  |  |  | $user_defined{$java_class};
58 |  |  |  |  | }
59 |  |  |  |  |
60 | 1 | 3µs |  |  | 1;
61 |  |  |  |  |
62 |  |  |  |  |
63 |  |  |  |  | =head1 NAME
64 |  |  |  |  |
65 |  |  |  |  | Log::Log4perl::JavaMap - maps java log4j appenders to Log::Dispatch classes
66 |  |  |  |  |
67 |  |  |  |  | =head1 SYNOPSIS
68 |  |  |  |  |
69 |  |  |  |  | ###############################
70 |  |  |  |  | log4j.appender.FileAppndr1 = org.apache.log4j.FileAppender
71 |  |  |  |  | log4j.appender.FileAppndr1.File = /var/log/onetime.log
72 |  |  |  |  | log4j.appender.FileAppndr1.Append = false
73 |  |  |  |  |
74 |  |  |  |  | log4j.appender.FileAppndr1.layout = org.apache.log4j.PatternLayout
75 |  |  |  |  | log4j.appender.FileAppndr1.layout.ConversionPattern=%d %4r [%t] %-5p %c %x - %m%n
76 |  |  |  |  | ###############################
77 |  |  |  |  |
78 |  |  |  |  |
79 |  |  |  |  | =head1 DESCRIPTION
80 |  |  |  |  |
81 |  |  |  |  | If somebody wants to create an appender called C<org.apache.log4j.ConsoleAppender>,
82 |  |  |  |  | we want to translate it to Log::Dispatch::Screen, and then translate
83 |  |  |  |  | the log4j options into Log::Dispatch parameters..
84 |  |  |  |  |
85 |  |  |  |  | =head2 What's Implemented
86 |  |  |  |  |
87 |  |  |  |  | (Note that you can always use the Log::Dispatch::* module. By 'implemented'
88 |  |  |  |  | I mean having a translation class that translates log4j options into
89 |  |  |  |  | the Log::Dispatch options so you can use log4j rather than log4perl
90 |  |  |  |  | syntax in your config file.)
91 |  |  |  |  |
92 |  |  |  |  | Here's the list of appenders I see on the current (6/2002) log4j site.
93 |  |  |  |  |
94 |  |  |  |  | These are implemented
95 |  |  |  |  |
96 |  |  |  |  | ConsoleAppender - Log::Dispatch::Screen
97 |  |  |  |  | FileAppender - Log::Dispatch::File
98 |  |  |  |  | RollingFileAppender - Log::Dispatch::FileRotate (by Mark Pfeiffer)
99 |  |  |  |  | JDBCAppender - Log::Log4perl::Appender::DBI
100 |  |  |  |  | SyslogAppender - Log::Dispatch::Syslog
101 |  |  |  |  | NTEventLogAppender - Log::Dispatch::Win32EventLog
102 |  |  |  |  |
103 |  |  |  |  |
104 |  |  |  |  | These should/will/might be implemented
105 |  |  |  |  |
106 |  |  |  |  | DailyRollingFileAppender -
107 |  |  |  |  | SMTPAppender - Log::Dispatch::Email::MailSender
108 |  |  |  |  |
109 |  |  |  |  |
110 |  |  |  |  | These might be implemented but they don't have corresponding classes
111 |  |  |  |  | in Log::Dispatch (yet):
112 |  |  |  |  |
113 |  |  |  |  | NullAppender
114 |  |  |  |  | TelnetAppender
115 |  |  |  |  |
116 |  |  |  |  | These might be simulated
117 |  |  |  |  |
118 |  |  |  |  | LF5Appender - use Tk?
119 |  |  |  |  | ExternallyRolledFileAppender - catch a HUP instead?
120 |  |  |  |  |
121 |  |  |  |  | These will probably not be implemented
122 |  |  |  |  |
123 |  |  |  |  | AsyncAppender
124 |  |  |  |  | JMSAppender
125 |  |  |  |  | SocketAppender - (ships a serialized LoggingEvent to the server side)
126 |  |  |  |  | SocketHubAppender
127 |  |  |  |  |
128 |  |  |  |  | =head1 ROLL YOUR OWN
129 |  |  |  |  |
130 |  |  |  |  | Let's say you've in a mixed Java/Perl enviroment and you've
131 |  |  |  |  | come up with some custom Java appender with behavior you want to
132 |  |  |  |  | use in both worlds, C<myorg.customAppender>. You write a
133 |  |  |  |  | Perl appender with the same behavior C<Myorg::CustomAppender>. You
134 |  |  |  |  | want to use one config file accross both applications, so the
135 |  |  |  |  | config file will have to say 'myorg.customAppender'. But
136 |  |  |  |  | the mapping from C<myorg.customAppender> to C<Myorg::CustomAppender>
137 |  |  |  |  | isn't in this JavaMap class, so what do you do?
138 |  |  |  |  |
139 |  |  |  |  | In your Perl code, before you call Log::Log4perl::init(), do this:
140 |  |  |  |  |
141 |  |  |  |  | $Log::Log4perl::JavaMap::user_defined{'myorg.customAppender'} =
142 |  |  |  |  | 'Myorg::CustomAppender';
143 |  |  |  |  |
144 |  |  |  |  | and you can use 'myorg.customAppender' in your config file with
145 |  |  |  |  | impunity.
146 |  |  |  |  |
147 |  |  |  |  | =head1 SEE ALSO
148 |  |  |  |  |
149 |  |  |  |  | http://jakarta.apache.org/log4j/docs/
150 |  |  |  |  |
151 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
152 |  |  |  |  |
153 |  |  |  |  | Copyright 2002-2009 by Mike Schilli E<lt>m@perlmeister.comE<gt>
154 |  |  |  |  | and Kevin Goess E<lt>cpan@goess.orgE<gt>.
155 |  |  |  |  |
156 |  |  |  |  | This library is free software; you can redistribute it and/or modify
157 |  |  |  |  | it under the same terms as Perl itself.
158 |  |  |  |  |
159 |  |  |  |  | =cut