| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | use Carp; | 
| 3 | 70 |  |  | 70 |  | 497 | use strict; | 
|  | 70 |  |  |  |  | 152 |  | 
|  | 70 |  |  |  |  | 4551 |  | 
| 4 | 70 |  |  | 70 |  | 437 |  | 
|  | 70 |  |  |  |  | 205 |  | 
|  | 70 |  |  |  |  | 1700 |  | 
| 5 |  |  |  |  |  |  | use constant _INTERNAL_DEBUG => 0; | 
| 6 | 70 |  |  | 70 |  | 383 |  | 
|  | 70 |  |  |  |  | 184 |  | 
|  | 70 |  |  |  |  | 27001 |  | 
| 7 |  |  |  |  |  |  | our %translate = ( | 
| 8 |  |  |  |  |  |  | 'org.apache.log4j.ConsoleAppender' => | 
| 9 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::ConsoleAppender', | 
| 10 |  |  |  |  |  |  | 'org.apache.log4j.FileAppender'    => | 
| 11 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::FileAppender', | 
| 12 |  |  |  |  |  |  | 'org.apache.log4j.RollingFileAppender'    => | 
| 13 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::RollingFileAppender', | 
| 14 |  |  |  |  |  |  | 'org.apache.log4j.TestBuffer'    => | 
| 15 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::TestBuffer', | 
| 16 |  |  |  |  |  |  | 'org.apache.log4j.jdbc.JDBCAppender'    => | 
| 17 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::JDBCAppender', | 
| 18 |  |  |  |  |  |  | 'org.apache.log4j.SyslogAppender'    => | 
| 19 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::SyslogAppender', | 
| 20 |  |  |  |  |  |  | 'org.apache.log4j.NTEventLogAppender'    => | 
| 21 |  |  |  |  |  |  | 'Log::Log4perl::JavaMap::NTEventLogAppender', | 
| 22 |  |  |  |  |  |  | ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | our %user_defined; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my ($appender_name, $appender_data) = @_; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 13 |  |  | 13 | 0 | 38 | print "Trying to map $appender_name\n" if _INTERNAL_DEBUG; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 13 |  |  |  |  | 83 | $appender_data->{value} || | 
| 31 |  |  |  |  |  |  | die "ERROR: you didn't tell me how to implement your appender " . | 
| 32 |  |  |  |  |  |  | "'$appender_name'"; | 
| 33 | 13 | 50 |  |  |  | 43 |  | 
| 34 |  |  |  |  |  |  | my $perl_class = $translate{$appender_data->{value}} || | 
| 35 |  |  |  |  |  |  | $user_defined{$appender_data->{value}} || | 
| 36 |  |  |  |  |  |  | die "ERROR:  I don't know how to make a '$appender_data->{value}' " . | 
| 37 |  |  |  |  |  |  | "to implement your appender '$appender_name', that's not a " . | 
| 38 | 13 |  | 50 |  |  | 71 | "supported class\n"; | 
| 39 |  |  |  |  |  |  | eval { | 
| 40 |  |  |  |  |  |  | eval "require $perl_class";  #see 'perldoc -f require' for why two evals | 
| 41 | 13 |  |  |  |  | 38 | die $@ if $@; | 
| 42 | 13 |  |  |  |  | 953 | }; | 
| 43 | 13 | 50 |  |  |  | 83 | $@ and die "ERROR: trying to set appender for $appender_name to " . | 
| 44 |  |  |  |  |  |  | "$appender_data->{value} using $perl_class failed\n$@  \n"; | 
| 45 | 13 | 50 |  |  |  | 46 |  | 
| 46 |  |  |  |  |  |  | my $app = $perl_class->new($appender_name, $appender_data); | 
| 47 |  |  |  |  |  |  | return $app; | 
| 48 | 13 |  |  |  |  | 99 | } | 
| 49 | 13 |  |  |  |  | 49 |  | 
| 50 |  |  |  |  |  |  | #an external api to the two hashes | 
| 51 |  |  |  |  |  |  | my $java_class = shift; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | return $translate{$java_class} || | 
| 54 | 193 |  |  | 193 | 0 | 401 | $user_defined{$java_class}; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 193 |  | 66 |  |  | 1024 | 1; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =encoding utf8 | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head1 NAME | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | Log::Log4perl::JavaMap - maps java log4j appenders to Log::Dispatch classes | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | ############################### | 
| 69 |  |  |  |  |  |  | log4j.appender.FileAppndr1        = org.apache.log4j.FileAppender | 
| 70 |  |  |  |  |  |  | log4j.appender.FileAppndr1.File   = /var/log/onetime.log | 
| 71 |  |  |  |  |  |  | log4j.appender.FileAppndr1.Append = false | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | log4j.appender.FileAppndr1.layout = org.apache.log4j.PatternLayout | 
| 74 |  |  |  |  |  |  | log4j.appender.FileAppndr1.layout.ConversionPattern=%d %4r [%t] %-5p %c %x - %m%n | 
| 75 |  |  |  |  |  |  | ############################### | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | If somebody wants to create an appender called C<org.apache.log4j.ConsoleAppender>, | 
| 81 |  |  |  |  |  |  | we want to translate it to Log::Dispatch::Screen, and then translate | 
| 82 |  |  |  |  |  |  | the log4j options into Log::Dispatch parameters.. | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head2 What's Implemented | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | (Note that you can always use the Log::Dispatch::* module.  By 'implemented' | 
| 87 |  |  |  |  |  |  | I mean having a translation class that translates log4j options into | 
| 88 |  |  |  |  |  |  | the Log::Dispatch options so you can use log4j rather than log4perl | 
| 89 |  |  |  |  |  |  | syntax in your config file.) | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | Here's the list of appenders I see on the current (6/2002) log4j site. | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | These are implemented | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | ConsoleAppender     - Log::Dispatch::Screen | 
| 96 |  |  |  |  |  |  | FileAppender        - Log::Dispatch::File | 
| 97 |  |  |  |  |  |  | RollingFileAppender - Log::Dispatch::FileRotate (by Mark Pfeiffer) | 
| 98 |  |  |  |  |  |  | JDBCAppender        - Log::Log4perl::Appender::DBI | 
| 99 |  |  |  |  |  |  | SyslogAppender      - Log::Dispatch::Syslog | 
| 100 |  |  |  |  |  |  | NTEventLogAppender  - Log::Dispatch::Win32EventLog | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | These should/will/might be implemented | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | DailyRollingFileAppender - | 
| 106 |  |  |  |  |  |  | SMTPAppender     - Log::Dispatch::Email::MailSender | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | These might be implemented but they don't have corresponding classes | 
| 110 |  |  |  |  |  |  | in Log::Dispatch (yet): | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | NullAppender | 
| 113 |  |  |  |  |  |  | TelnetAppender | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | These might be simulated | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | LF5Appender - use Tk? | 
| 118 |  |  |  |  |  |  | ExternallyRolledFileAppender - catch a HUP instead? | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | These will probably not be implemented | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | AsyncAppender | 
| 123 |  |  |  |  |  |  | JMSAppender | 
| 124 |  |  |  |  |  |  | SocketAppender - (ships a serialized LoggingEvent to the server side) | 
| 125 |  |  |  |  |  |  | SocketHubAppender | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head1 ROLL YOUR OWN | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | Let's say you've in a mixed Java/Perl environment and you've | 
| 130 |  |  |  |  |  |  | come up with some custom Java appender with behavior you want to | 
| 131 |  |  |  |  |  |  | use in both worlds, C<myorg.customAppender>.  You write a | 
| 132 |  |  |  |  |  |  | Perl appender with the same behavior C<Myorg::CustomAppender>. You | 
| 133 |  |  |  |  |  |  | want to use one config file across both applications, so the | 
| 134 |  |  |  |  |  |  | config file will have to say 'myorg.customAppender'.  But | 
| 135 |  |  |  |  |  |  | the mapping from C<myorg.customAppender> to C<Myorg::CustomAppender> | 
| 136 |  |  |  |  |  |  | isn't in this JavaMap class, so what do you do? | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | In  your Perl code, before you call Log::Log4perl::init(), do this: | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | $Log::Log4perl::JavaMap::user_defined{'myorg.customAppender'} = | 
| 141 |  |  |  |  |  |  | 'Myorg::CustomAppender'; | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | and you can use 'myorg.customAppender' in your config file with | 
| 144 |  |  |  |  |  |  | impunity. | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | http://jakarta.apache.org/log4j/docs/ | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =head1 LICENSE | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | Copyright 2002-2013 by Mike Schilli E<lt>m@perlmeister.comE<gt> | 
| 153 |  |  |  |  |  |  | and Kevin Goess E<lt>cpan@goess.orgE<gt>. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 156 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =head1 AUTHOR | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | Please contribute patches to the project on Github: | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | http://github.com/mschilli/log4perl | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | Send bug reports or requests for enhancements to the authors via our | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | MAILING LIST (questions, bug reports, suggestions/patches): | 
| 167 |  |  |  |  |  |  | log4perl-devel@lists.sourceforge.net | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | Authors (please contact them via the list above, not directly): | 
| 170 |  |  |  |  |  |  | Mike Schilli <m@perlmeister.com>, | 
| 171 |  |  |  |  |  |  | Kevin Goess <cpan@goess.org> | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | Contributors (in alphabetical order): | 
| 174 |  |  |  |  |  |  | Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton | 
| 175 |  |  |  |  |  |  | Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony | 
| 176 |  |  |  |  |  |  | Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy | 
| 177 |  |  |  |  |  |  | Grundman, Paul Harrington, Alexander Hartmaier  David Hull, | 
| 178 |  |  |  |  |  |  | Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, | 
| 179 |  |  |  |  |  |  | Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, | 
| 180 |  |  |  |  |  |  | Lars Thegler, David Viner, Mac Yang. | 
| 181 |  |  |  |  |  |  |  |