Log::Log4perl::Appender::Chunk - Group log messages in Identified chunks
This appender will write group of Log lines (chunks) to the underlying store under an ID that you choose.
A number of Store classes are shipped ( in Log::Log4perl::Appender::Chunk::Store::* ), but it's very easy to write your own store, as it's essentially a Key/Value storage.
See Log::Log4perl::Appender::Chunk::Store for more details.
Marking chunks of log rely on the Log4perl Mapped Diagnostic Context (MDC) mechanism. See Log::Log4perl::MDC
Essentially, each time you set a MDC key 'chunk' to something, this appender will start recording chunks and fetch them to the storage when the key 'chunk' is unset or changes.
Anywhere in your code:
# .. Use log4perl as usual .. ## Start capturing Log lines in an identified Chunk Log::Log4perl::MDC->put('chunk', "Your-Log-Chunk-Unique-ID-Key"); # .. Use Log4perl as usual .. ## Finish capturing in the identified Chunk Log::Log4perl::MDC->put('chunk',undef); # .. Use Log4perl as usual ..
Then depending on the configured store, you will be able to retrieve your log chunks from different places. See below.
Reference: Log::Log4perl::Appender::Chunk::Store::Memory
log4perl.conf:
log4perl.rootLogger=TRACE, Chunk log4perl.appender.Chunk=Log::Log4perl::Appender::Chunk # Built-in store class S3 log4perl.appender.Chunk.store_class=Memory # Etc.. log4perl.appender.Chunk.layout=..
log4perl.rootLogger=TRACE, Chunk log4perl.appender.Chunk=Log::Log4perl::Appender::Chunk # Built-in store class S3 log4perl.appender.Chunk.store_class=S3 # S3 Specific Arguments: log4perl.appender.Chunk.store_args.bucket_name=MyLogChunks log4perl.appender.Chunk.store_args.aws_access_key_id=YourAWSAccessKey log4perl.appender.Chunk.store_args.aws_secret_access_key=YourAWS # Optional: log4perl.appender.Chunk.store_args.retry=1 log4perl.appender.Chunk.store_args.vivify_bucket=1 log4perl.appender.Chunk.store_args.expires_in_days=3 log4perl.appender.Chunk.store_args.acl_short=public-read # Etc.. log4perl.appender.Chunk.layout=...
Log::Log4perl::Appender framework method.
The instance of Log::Log4perl::Appender::Chunk::Store this logger uses.
It's usually configured from the Log4perl configuration file as shown in the SYNOPSIS, but you can also inject it from your application code:
Log::Log4perl->appender_by_name('Chunk')->store($your_instance_of_storage);
Will attempt to store whatever is left in the buffer if your program finishes before it could output any log file outside a Chunk capturing section.
To install Log::Log4perl::Appender::Chunk, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Log4perl::Appender::Chunk
CPAN shell
perl -MCPAN -e shell install Log::Log4perl::Appender::Chunk
For more information on module installation, please visit the detailed CPAN module installation guide.