@@ -2,6 +2,20 @@
Revision history for Log::Log4perl
##################################################
+1.45 (2014/10/25)
+ * (ms) fgeueke provided a pull request for short-circuiting boolean
+ filters: https://github.com/mschilli/log4perl/pull/48
+ * (ms) [rt.cpan.org #94009] Tim Bunce had requested that the
+ PatternLayout's %m specifier allow for fixed indentation,
+ variable indentation, and at the same time permit the use
+ of the chomp option. Added with tests and docs.
+ * (ms) Gianni Ceccarelli added the log4perl.utcDateTimes config
+ option to select UTC instead of localtime:
+ https://github.com/mschilli/log4perl/pull/53
+ * (ms) @bokutin fixed Catalyst.pm buffer flush:
+ https://github.com/mschilli/log4perl/pull/51
+ https://github.com/mschilli/log4perl/issues/54
+
1.44 (2014/05/17)
* (ms) Skipped mkpath umask tests on Win32 which doesn't support it
properly.
@@ -149,6 +149,8 @@ t/065Undef.t
t/066SQLite.t
t/067Exception.t
t/068MultilineIndented.t
+t/069MoreMultiline.t
+t/070UTCDate.t
t/compare.pl
t/deeper1.expected
t/deeper6.expected
@@ -4,7 +4,7 @@
"Mike Schilli <m@perlmeister.com>"
],
"dynamic_config" : 1,
- "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.131560",
+ "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.142690",
"license" : [
"unknown"
],
@@ -45,5 +45,5 @@
},
"x_MailingList" : "mailto:log4perl-devel@lists.sourceforge.net"
},
- "version" : "1.44"
+ "version" : "1.45"
}
@@ -3,25 +3,25 @@ abstract: 'Log4j implementation for Perl'
author:
- 'Mike Schilli <m@perlmeister.com>'
build_requires:
- ExtUtils::MakeMaker: 0
+ ExtUtils::MakeMaker: '0'
configure_requires:
- ExtUtils::MakeMaker: 0
+ ExtUtils::MakeMaker: '0'
dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.131560'
+generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.142690'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
+ version: '1.4'
name: Log-Log4perl
no_index:
directory:
- t
- inc
requires:
- File::Path: 2.0606
- File::Spec: 0.82
- Test::More: 0.45
+ File::Path: '2.0606'
+ File::Spec: '0.82'
+ Test::More: '0.45'
resources:
MailingList: mailto:log4perl-devel@lists.sourceforge.net
repository: http://github.com/mschilli/log4perl
-version: 1.44
+version: '1.45'
@@ -1,5 +1,5 @@
######################################################################
- Log::Log4perl 1.44
+ Log::Log4perl 1.45
######################################################################
NAME
@@ -52,7 +52,7 @@ DESCRIPTION
For a detailed tutorial on Log::Log4perl usage, please read
- http://www.perl.com/pub/a/2002/09/11/log4perl.html
+ <http://www.perl.com/pub/a/2002/09/11/log4perl.html>
Logging beats a debugger if you want to know what's going on in your
code during runtime. However, traditional logging packages are too
@@ -515,9 +515,9 @@ How to use it
The root logger defines two appenders here: "stdout", which uses
"org.apache.log4j.ConsoleAppender" (ultimately mapped by "Log::Log4perl"
- to "Log::Log4perl::Appender::Screen") to write to the screen. And "R", a
+ to Log::Log4perl::Appender::Screen) to write to the screen. And "R", a
"org.apache.log4j.RollingFileAppender" (mapped by "Log::Log4perl" to
- "Log::Dispatch::FileRotate" with the "File" attribute specifying the log
+ Log::Dispatch::FileRotate with the "File" attribute specifying the log
file.
See Log::Log4perl::Config for more examples and syntax explanations.
@@ -574,8 +574,8 @@ How to use it
Also, %d can be fine-tuned to display only certain characteristics
of a date, according to the SimpleDateFormat in the Java World
- (http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.ht
- ml)
+ (<http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.h
+ tml>)
In this way, %d{HH:mm} displays only hours and minutes of the
current date, while %d{yy, EEEE} displays a two-digit year, followed
@@ -618,8 +618,11 @@ How to use it
For more details on logging and how to use the flexible and the simple
format, check out the original "log4j" website under
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/SimpleLayout.html
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
+ SimpleLayout
+ <http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/SimpleLayo
+ ut.html> and PatternLayout
+ <http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLay
+ out.html>
Penalties
Logging comes with a price tag. "Log::Log4perl" has been optimized to
@@ -952,7 +955,7 @@ Categories
Cool Tricks
Here's a collection of useful tricks for the advanced "Log::Log4perl"
user. For more, check the FAQ, either in the distribution
- (Log::Log4perl::FAQ) or on http://log4perl.sourceforge.net.
+ (Log::Log4perl::FAQ) or on <http://log4perl.sourceforge.net>.
Shortcuts
When getting an instance of a logger, instead of saying
@@ -2123,9 +2126,9 @@ INSTALLATION
DEVELOPMENT
Log::Log4perl is still being actively developed. We will always make
sure the test suite (approx. 500 cases) will pass, but there might still
- be bugs. please check http://github.com/mschilli/log4perl for the latest
- release. The api has reached a mature state, we will not change it
- unless for a good reason.
+ be bugs. please check <http://github.com/mschilli/log4perl> for the
+ latest release. The api has reached a mature state, we will not change
+ it unless for a good reason.
Bug reports and feedback are always welcome, just email them to our
mailing list shown in the AUTHORS section. We're usually addressing them
@@ -2134,15 +2137,15 @@ DEVELOPMENT
REFERENCES
[1] Michael Schilli, "Retire your debugger, log smartly with
Log::Log4perl!", Tutorial on perl.com, 09/2002,
- http://www.perl.com/pub/a/2002/09/11/log4perl.html
+ <http://www.perl.com/pub/a/2002/09/11/log4perl.html>
[2] Ceki Gülcü, "Short introduction to log4j",
- http://logging.apache.org/log4j/1.2/manual.html
+ <http://logging.apache.org/log4j/1.2/manual.html>
[3] Vipan Singla, "Don't Use System.out.println! Use Log4j.",
- http://www.vipan.com/htdocs/log4jhelp.html
+ <http://www.vipan.com/htdocs/log4jhelp.html>
- [4] The Log::Log4perl project home page: http://log4perl.com
+ [4] The Log::Log4perl project home page: <http://log4perl.com>
SEE ALSO
Log::Log4perl::Config, Log::Log4perl::Appender,
@@ -123,21 +123,24 @@ sub _flush {
for my $appender (values %Log::Log4perl::Logger::APPENDER_BY_NAME) {
next if $appender->{name} !~ /_$CATALYST_APPENDER_SUFFIX$/;
- $appender->flush();
+
+ if ($self->abort) {
+ $appender->{appender}{buffer} = [];
+ }
+ else {
+ $appender->flush();
+ }
}
+
+ $self->abort(undef);
}
##################################################
sub abort {
##################################################
- my($self, $abort) = @_;
+ my $self = shift;
- $self->{abort} = $abort;
-
- for my $appender (values %Log::Log4perl::Logger::APPENDER_BY_NAME) {
- next if $appender->{name} !~ /_$CATALYST_APPENDER_SUFFIX$/;
- $appender->{buffer} = [];
- }
+ $self->{abort} = $_[0] if @_;
return $self->{abort};
}
@@ -218,7 +221,7 @@ Level-based control is available via the following methods:
$c->log->error("Can't add user ", $user);
$c->log->fatal("Database down, aborting request");
-But that's no all, Log4perl is much more powerful.
+But that's not all, Log4perl is much more powerful.
The logging statement can be suppressed or activated based on a Log4perl
file that looks like
@@ -238,7 +241,7 @@ log-level and location filtering, and how to forward messages not only
to the screen or to log files, but also to databases, email appenders,
and much more.
-Also, you can vary the layout of each message. For example if you want
+Also, you can change the message layout. For example if you want
to know where a particular statement was logged, turn on file names and
line numbers:
@@ -278,8 +281,8 @@ options.
If called without parameters, new() initializes Log4perl in a way
so that messages are logged similarly to Catalyst's default logging
-mechanism. If you provide configuration, either the name of a configuration
-file or a reference to scalar string containing the configuration, it
+mechanism. If you provide a configuration, either the name of a configuration
+file or a reference to a scalar string containing the configuration, it
will call Log4perl with these parameters.
The second (optional) parameter is a list of key/value pairs:
@@ -179,6 +179,11 @@ sub _init {
$data->{oneMessagePerAppender}->{value};
}
+ if(exists $data->{utcDateTimes}) {
+ require Log::Log4perl::DateFormat;
+ $Log::Log4perl::DateFormat::GMTIME = !!$data->{utcDateTimes}->{value};
+ }
+
# Boolean filters
my %boolean_filters = ();
@@ -2308,6 +2308,10 @@ noticeable performance impact.
If a layout defines a date, Log::Log4perl uses local time to populate it.
If you want UTC instead, set
+ log4perl.utcDateTimes = 1
+
+in your configuration. Alternatively, you can set
+
$Log::Log4perl::DateFormat::GMTIME = 1;
in your program before the first log statement.
@@ -60,9 +60,9 @@ sub compile_logic {
# Fabricate a parameter list: A1/A2/A3 => $A1, $A2, $A3
my $plist = join ', ', map { '$' . $_ } keys %{$self->{params}};
- # Replace all the (dollar-less) placeholders in the code
- # by scalars (basically just put dollars in front of them)
- $logic =~ s/([\w_-]+)/\$$1/g;
+ # Replace all the (dollar-less) placeholders in the code with
+ # calls to their respective coderefs.
+ $logic =~ s/([\w_-]+)/\&\$$1/g;
# Set up the meta decider, which transforms the config file
# logic into compiled perl code
@@ -95,9 +95,12 @@ sub eval_logic {
# in the code (although the order of keys is
# not predictable, it is consistent :)
for my $param (keys %{$self->{params}}) {
- # Call ok() and map the result to 1 or 0
- print "Calling filter $param\n" if _INTERNAL_DEBUG;
- push @plist, ($self->{params}->{$param}->ok(%$p) ? 1 : 0);
+ # Pass a coderef as a param that will run the filter's ok method and
+ # return a 1 or 0.
+ print "Passing filter $param\n" if _INTERNAL_DEBUG;
+ push(@plist, sub {
+ return $self->{params}->{$param}->ok(%$p) ? 1 : 0
+ });
}
# Now pipe the parameters into the canned function,
@@ -26,10 +26,18 @@ sub new {
$facility = 'user';
}
+ if (defined $data->{Ident}{value}) {
+ $ident = $data->{Ident}{value}
+ }elsif (defined $data->{ident}{value}){
+ $ident = $data->{ident}{value};
+ }else{
+ $ident = $0;
+ }
return Log::Log4perl::Appender->new("Log::Dispatch::Syslog",
name => $appender_name,
facility => $facility,
+ ident => $ident,
min_level => 'debug',
);
}
@@ -9,7 +9,6 @@ use warnings;
use constant _INTERNAL_DEBUG => 0;
use Carp;
-use Log::Log4perl;
use Log::Log4perl::Util;
use Log::Log4perl::Level;
use Log::Log4perl::DateFormat;
@@ -133,22 +132,42 @@ sub rep {
# If it's a %d{...} construct, initialize a simple date
# format formatter, so that we can quickly render later on.
# If it's just %d, assume %d{yyyy/MM/dd HH:mm:ss}
- my $sdf;
if($op eq "d") {
if(defined $curlies) {
- $sdf = Log::Log4perl::DateFormat->new($curlies);
+ $curlies = Log::Log4perl::DateFormat->new($curlies);
} else {
- $sdf = Log::Log4perl::DateFormat->new("yyyy/MM/dd HH:mm:ss");
+ $curlies = Log::Log4perl::DateFormat->new("yyyy/MM/dd HH:mm:ss");
}
+ } elsif($op eq "m") {
+ $curlies = $self->curlies_csv_parse($curlies);
}
- push @{$self->{stack}}, [$op, $sdf || $curlies];
+ push @{$self->{stack}}, [$op, $curlies];
$self->{info_needed}->{$op}++;
return "%${num}s";
}
+###########################################
+sub curlies_csv_parse {
+###########################################
+ my($self, $curlies) = @_;
+
+ my $data = {};
+
+ if(defined $curlies and length $curlies) {
+ $curlies =~ s/\s//g;
+
+ for my $field (split /,/, $curlies) {
+ my($key, $value) = split /=/, $field;
+ $data->{$key} = $value;
+ }
+ }
+
+ return $data;
+}
+
##################################################
sub render {
##################################################
@@ -324,12 +343,19 @@ sub curly_action {
} elsif($ops eq "M") {
$data = shrink_category($data, $curlies);
} elsif($ops eq "m") {
- if($curlies eq "chomp") {
+ if(exists $curlies->{chomp}) {
chomp $data;
- } elsif( $curlies eq "indent" ) {
- no warnings; # trailing array elements are undefined
- my $indent = length sprintf $printformat, @$results;
- $data =~ s/\n/ "\n" . (" " x $indent)/ge;
+ }
+ if(exists $curlies->{indent}) {
+ if(defined $curlies->{indent}) {
+ # fixed indent
+ $data =~ s/\n/ "\n" . (" " x $curlies->{indent})/ge;
+ } else {
+ # indent on the lead-in
+ no warnings; # trailing array elements are undefined
+ my $indent = length sprintf $printformat, @$results;
+ $data =~ s/\n/ "\n" . (" " x $indent)/ge;
+ }
}
} elsif($ops eq "F") {
my @parts = File::Spec->splitdir($data);
@@ -538,8 +564,9 @@ replaced by the logging engine when it's time to log the message:
parentheses.
%L Line number within the file where the log statement was issued
%m The message to be logged
- %m{chomp} The message to be logged, stripped off a trailing newline
- %m{indent} Log message, indented if mult-line
+ %m{chomp} Log message, stripped off a trailing newline
+ %m{indent} Log message, multi-lines indented so they line up with first
+ %m{indent=n} Log message, multi-lines indented by n spaces
%M Method or function where the logging request was issued
%n Newline (OS-independent)
%p Priority of the logging event (%p{1} shows the first letter)
@@ -793,6 +820,40 @@ This will add a single newline to every message, regardless if it
complies with the Log4perl newline guidelines or not (thanks to
Tim Bunce for this idea).
+=head2 Multi Lines
+
+If a log message consists of several lines, like
+
+ $logger->debug("line1\nline2\nline3");
+
+then by default, they get logged like this (assuming the the layout is
+set to "%d>%m%n"):
+
+ # layout %d>%m%n
+ 2014/07/27 12:46:16>line1
+ line2
+ line3
+
+If you'd rather have the messages aligned like
+
+ # layout %d>%m{indent}%n
+ 2014/07/27 12:46:16>line1
+ line2
+ line3
+
+then use the C<%m{indent}> option for the %m specifier. This option
+can also take a fixed value, as in C<%m{indent=2}>, which indents
+subsequent lines by two spaces:
+
+ # layout %d>%m{indent=2}%n
+ 2014/07/27 12:46:16>line1
+ line2
+ line3
+
+Note that you can still add the C<chomp> option for the C<%m> specifier
+in this case (see above what it does), simply add it after a
+separating comma, like in C<%m{indent=2,chomp}>.
+
=head1 LICENSE
Copyright 2002-2013 by Mike Schilli E<lt>m@perlmeister.comE<gt>
@@ -14,7 +14,7 @@ use Log::Log4perl::Level;
use Log::Log4perl::Config;
use Log::Log4perl::Appender;
-our $VERSION = '1.44';
+our $VERSION = '1.45';
# set this to '1' if you're using a wrapper
# around Log::Log4perl
@@ -671,7 +671,7 @@ of your system from the outside. It implements the widely popular
B<For a detailed tutorial on Log::Log4perl usage, please read>
- http://www.perl.com/pub/a/2002/09/11/log4perl.html
+L<http://www.perl.com/pub/a/2002/09/11/log4perl.html>
Logging beats a debugger if you want to know what's going on
in your code during runtime. However, traditional logging packages
@@ -1168,10 +1168,10 @@ Third example:
The root logger defines two appenders here: C<stdout>, which uses
C<org.apache.log4j.ConsoleAppender> (ultimately mapped by C<Log::Log4perl>
-to C<Log::Log4perl::Appender::Screen>) to write to the screen. And
+to L<Log::Log4perl::Appender::Screen>) to write to the screen. And
C<R>, a C<org.apache.log4j.RollingFileAppender>
(mapped by C<Log::Log4perl> to
-C<Log::Dispatch::FileRotate> with the C<File> attribute specifying the
+L<Log::Dispatch::FileRotate> with the C<File> attribute specifying the
log file.
See L<Log::Log4perl::Config> for more examples and syntax explanations.
@@ -1233,7 +1233,7 @@ and L<"Mapped Diagnostic Context (MDC)">.
Also, C<%d> can be fine-tuned to display only certain characteristics
of a date, according to the SimpleDateFormat in the Java World
-(http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html)
+(L<http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html>)
In this way, C<%d{HH:mm}> displays only hours and minutes of the current date,
while C<%d{yy, EEEE}> displays a two-digit year, followed by a spelled-out
@@ -1276,8 +1276,9 @@ tradition, C<%-20c> will reserve 20 chars for the category and left-justify it.
For more details on logging and how to use the flexible and the simple
format, check out the original C<log4j> website under
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/SimpleLayout.html
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
+L<SimpleLayout|http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/SimpleLayout.html>
+and
+L<PatternLayout|http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html>
=head2 Penalties
@@ -1639,7 +1640,7 @@ document in the Log::Log4perl distribution.
Here's a collection of useful tricks for the advanced C<Log::Log4perl> user.
For more, check the FAQ, either in the distribution
-(L<Log::Log4perl::FAQ>) or on http://log4perl.sourceforge.net.
+(L<Log::Log4perl::FAQ>) or on L<http://log4perl.sourceforge.net>.
=head2 Shortcuts
@@ -2877,7 +2878,7 @@ Manual installation works as usual with
Log::Log4perl is still being actively developed. We will
always make sure the test suite (approx. 500 cases) will pass, but there
-might still be bugs. please check http://github.com/mschilli/log4perl
+might still be bugs. please check L<http://github.com/mschilli/log4perl>
for the latest release. The api has reached a mature state, we will
not change it unless for a good reason.
@@ -2893,21 +2894,21 @@ them immediately.
Michael Schilli, "Retire your debugger, log smartly with Log::Log4perl!",
Tutorial on perl.com, 09/2002,
-http://www.perl.com/pub/a/2002/09/11/log4perl.html
+L<http://www.perl.com/pub/a/2002/09/11/log4perl.html>
=item [2]
Ceki Gülcü, "Short introduction to log4j",
-http://logging.apache.org/log4j/1.2/manual.html
+L<http://logging.apache.org/log4j/1.2/manual.html>
=item [3]
Vipan Singla, "Don't Use System.out.println! Use Log4j.",
-http://www.vipan.com/htdocs/log4jhelp.html
+L<http://www.vipan.com/htdocs/log4jhelp.html>
=item [4]
-The Log::Log4perl project home page: http://log4perl.com
+The Log::Log4perl project home page: L<http://log4perl.com>
=back
@@ -13,7 +13,7 @@ BEGIN {
use warnings;
use strict;
-use Test::More tests => 32;
+use Test::More tests => 36;
use Log::Log4perl;
@@ -430,3 +430,87 @@ EOT
};
like $@, qr/Unknown parameter: LevelToWomper/, "Unknown parameter check";
+
+#############################################
+# AND-Shortcut with boolean filters
+#############################################
+my $counter = 0;
+no warnings qw( redefine );
+my $old_level_match_ok = *{ Log::Log4perl::Filter::LevelMatch::ok };
+*{ Log::Log4perl::Filter::LevelMatch::ok } = sub {
+ $counter++; 0 };
+
+Log::Log4perl->init(\ <<'EOT');
+log4perl.category.Some.Where = DEBUG, A1
+
+log4perl.filter.Debug = Log::Log4perl::Filter::LevelMatch
+log4perl.filter.Debug.LevelToMatch = DEBUG
+log4perl.filter.Debug.AcceptOnMatch = true
+
+log4perl.filter.Info = Log::Log4perl::Filter::LevelMatch
+log4perl.filter.Info.LevelToMatch = INFO
+log4perl.filter.Info.AcceptOnMatch = true
+
+log4perl.filter.MyBoolean = Log::Log4perl::Filter::Boolean
+log4perl.filter.MyBoolean.logic = Debug && Info
+
+log4perl.appender.A1 = Log::Log4perl::Appender::TestBuffer
+log4perl.appender.A1.Filter = MyBoolean
+log4perl.appender.A1.layout = Log::Log4perl::Layout::SimpleLayout
+EOT
+
+$buffer = Log::Log4perl::Appender::TestBuffer->by_name("A1");
+
+ # Define a logger
+$logger = Log::Log4perl->get_logger("Some.Where");
+
+ # Block it
+$logger->debug("some message");
+is($buffer->buffer(), "", "all blocked");
+is( $counter, 1, "shortcut ok" );
+$buffer->buffer("");
+
+Log::Log4perl->reset();
+$buffer->reset();
+
+#############################################
+# OR-Shortcut with boolean filters
+#############################################
+$counter = 0;
+*{ Log::Log4perl::Filter::LevelMatch::ok } = sub {
+ $counter++; 1 };
+
+Log::Log4perl->init(\ <<'EOT');
+log4perl.category.Some.Where = DEBUG, A1
+
+log4perl.filter.Debug = Log::Log4perl::Filter::LevelMatch
+log4perl.filter.Debug.LevelToMatch = DEBUG
+log4perl.filter.Debug.AcceptOnMatch = true
+
+log4perl.filter.Info = Log::Log4perl::Filter::LevelMatch
+log4perl.filter.Info.LevelToMatch = INFO
+log4perl.filter.Info.AcceptOnMatch = true
+
+log4perl.filter.MyBoolean = Log::Log4perl::Filter::Boolean
+log4perl.filter.MyBoolean.logic = Debug || Info
+
+log4perl.appender.A1 = Log::Log4perl::Appender::TestBuffer
+log4perl.appender.A1.Filter = MyBoolean
+log4perl.appender.A1.layout = Log::Log4perl::Layout::SimpleLayout
+EOT
+
+$buffer = Log::Log4perl::Appender::TestBuffer->by_name("A1");
+
+ # Define a logger
+$logger = Log::Log4perl->get_logger("Some.Where");
+
+ # Block it
+$logger->debug("some message");
+like($buffer->buffer(), qr/some message/, "all blocked");
+is( $counter, 1, "shortcut ok" );
+$buffer->buffer("");
+
+Log::Log4perl->reset();
+$buffer->reset();
+
+*{ Log::Log4perl::Filter::LevelMatch::ok } = $old_level_match_ok;
@@ -0,0 +1,54 @@
+use strict;
+use warnings;
+
+my $logfile = "./file.log";
+END { unlink $logfile; }
+
+use Log::Log4perl;
+use Log::Log4perl::Appender;
+use Log::Log4perl::Appender::TestBuffer;
+use Log::Log4perl::Layout::PatternLayout;
+
+use Test::More tests => 4;
+
+my $logger = Log::Log4perl->get_logger("blah");
+
+my $appender = Log::Log4perl::Appender->new(
+ "Log::Log4perl::Appender::TestBuffer",
+ name => 'testbuffer',
+);
+$logger->add_appender($appender);
+
+my $msg = "line1\nline2\nline3\n";
+my $logit = sub {
+ $appender->log({ level => 1, message => $msg }, 'foo_category', 'INFO');
+};
+
+# indent=fix
+my $layout = Log::Log4perl::Layout::PatternLayout->new("%m{indent=2}");
+$appender->layout($layout);
+$logit->();
+is $appender->buffer(), "line1\n line2\n line3\n ", "indent=2";
+$appender->buffer("");
+
+# indent=fix,chomp
+$layout = Log::Log4perl::Layout::PatternLayout->new("%m{indent=2,chomp}");
+$appender->layout($layout);
+$logit->();
+is $appender->buffer(), "line1\n line2\n line3", "indent=2,chomp";
+$appender->buffer("");
+
+# indent=variable
+$layout = Log::Log4perl::Layout::PatternLayout->new("123%m{indent}");
+$appender->layout($layout);
+$logit->();
+is $appender->buffer(), "123line1\n line2\n line3\n ", "indent";
+$appender->buffer("");
+
+# indent=variable,chomp
+$layout = Log::Log4perl::Layout::PatternLayout->new("123%m{indent,chomp}");
+$appender->layout($layout);
+$logit->();
+#print "[", $appender->buffer(), "]\n";
+is $appender->buffer(), "123line1\n line2\n line3", "indent,chomp";
+$appender->buffer("");
@@ -0,0 +1,63 @@
+###########################################
+# Tests for Log4perl::DateFormat
+# Gianni Ceccarelli, 2014 (dakkar@thenautilus.net)
+###########################################
+
+BEGIN {
+ if($ENV{INTERNAL_DEBUG}) {
+ require Log::Log4perl::InternalDebug;
+ Log::Log4perl::InternalDebug->enable();
+ }
+}
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { plan tests => 2 }
+
+use Log::Log4perl qw(get_logger);
+use Log::Log4perl::Appender::TestBuffer;
+
+sub init_with_utc {
+ my ($utc) = @_;
+ my $conf = <<'CONF';
+log4perl.category.Bar.Twix = WARN, Buffer
+log4perl.appender.Buffer = Log::Log4perl::Appender::TestBuffer
+log4perl.appender.Buffer.layout = \
+ Log::Log4perl::Layout::PatternLayout
+log4perl.appender.Buffer.layout.ConversionPattern = %d{HH:mm:ss}%n
+CONF
+ if (defined $utc) {
+ $conf .= "log4perl.utcDateTimes = $utc\n";
+ }
+
+ Log::Log4perl::init(\$conf);
+
+ return get_logger("Bar::Twix");
+}
+
+my $logger;
+sub log_string_for {
+ my $buffer = Log::Log4perl::Appender::TestBuffer->by_name("Buffer");
+ $buffer->clear();
+ $logger->error(@_);
+ return $buffer->buffer();
+}
+
+# default
+$logger = init_with_utc();
+my $default_string = log_string_for('blah');
+note "default: $default_string";
+
+$logger = init_with_utc(1);
+my $utc_string = log_string_for('blah');
+note "UTC: $utc_string";
+
+$logger = init_with_utc(0);
+my $local_string = log_string_for('blah');
+note "local: $local_string";
+
+is($default_string,$local_string,'use localtime by default');
+isnt($utc_string,$local_string,'gmtime != localtime');