1package Log::Log4perl::Appender::String; 2our @ISA = qw(Log::Log4perl::Appender); 3 4################################################## 5# Log dispatcher writing to a string buffer 6################################################## 7 8################################################## 9sub new { 10################################################## 11 my $proto = shift; 12 my $class = ref $proto || $proto; 13 my %params = @_; 14 15 my $self = { 16 name => "unknown name", 17 string => "", 18 %params, 19 }; 20 21 bless $self, $class; 22} 23 24################################################## 25sub log { 26################################################## 27 my $self = shift; 28 my %params = @_; 29 30 $self->{string} .= $params{message}; 31} 32 33################################################## 34sub string { 35################################################## 36 my($self, $new) = @_; 37 38 if(defined $new) { 39 $self->{string} = $new; 40 } 41 42 return $self->{string}; 43} 44 451; 46 47__END__ 48 49=head1 NAME 50 51Log::Log4perl::Appender::String - Append to a string 52 53=head1 SYNOPSIS 54 55 use Log::Log4perl::Appender::String; 56 57 my $appender = Log::Log4perl::Appender::String->new( 58 name => 'my string appender', 59 ); 60 61 # Append to the string 62 $appender->log( 63 message => "I'm searching the city for sci-fi wasabi\n" 64 ); 65 66 # Retrieve the result 67 my $result = $appender->string(); 68 69 # Reset the buffer to the empty string 70 $appender->string(""); 71 72=head1 DESCRIPTION 73 74This is a simple appender used internally by C<Log::Log4perl>. It 75appends messages to a scalar instance variable. 76 77=head1 LICENSE 78 79Copyright 2002-2012 by Mike Schilli E<lt>m@perlmeister.comE<gt> 80and Kevin Goess E<lt>cpan@goess.orgE<gt>. 81 82This library is free software; you can redistribute it and/or modify 83it under the same terms as Perl itself. 84 85=head1 AUTHOR 86 87Please contribute patches to the project on Github: 88 89 http://github.com/mschilli/log4perl 90 91Send bug reports or requests for enhancements to the authors via our 92 93MAILING LIST (questions, bug reports, suggestions/patches): 94log4perl-devel@lists.sourceforge.net 95 96Authors (please contact them via the list above, not directly): 97Mike Schilli <m@perlmeister.com>, 98Kevin Goess <cpan@goess.org> 99 100Contributors (in alphabetical order): 101Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton 102Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony 103Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy 104Grundman, Paul Harrington, David Hull, Robert Jacobson, Jason Kohles, 105Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik 106Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. 107 108