Log::Any::Plugin::Stringify - Custom argument stringification plugin for log adapters
version 0.012
# Set up some kind of logger use Log::Any::Adapter; Log::Any::Adapter->set('SomeAdapter'); # Apply your own argument stringifier. use Log::Any::Plugin; Log::Any::Plugin->add('Stringify', \&my_stringifier);
Log::Any logging functions are only defined to have a single $msg argument. Some adapters accept multiple arguments (like print does), but many don't. You may also want to do some sort of stringification of hash and list refs.
Log::Any::Plugin::Stringify allows you to inject an argument stringification function into every logging call, so that when you write this:
$log->error( ... );
you effectively get this:
$log->error( my_function( ... ) );
These configuration values are passed as key-value pairs: Log::Any::Plugin->add('Stringify', stringifier => \&my_func);
The stringifier function takes a list of arguments and should return a single string.
See default_stringifier below for the default stringifier behaviour.
There are no methods in this package which should be directly called by the user. Use Log::Any::Plugin->add() instead.
Private method called by Log::Any::Plugin->add()
The default stringifier if no custom stringifier is supplied.
Listrefs and hashrefs are expanded by Data::Dumper, and the whole lot is concatenated into one string.
The separator configuration argument can be used to customise how log arguments are separated from each other, e.g. trace("hello", "there", [1, 2, 2]) with a separator of '##' results in: hello##there##[1,2,2] -- the Dumper-driven output is not affected by the separator.
separator
trace("hello", "there", [1, 2, 2])
hello##there##[1,2,2]
Log::Any::Plugin
Thanks to Strategic Data for sponsoring the development of this module.
Stephen Thirlwall <sdt@cpan.org>
This software is copyright (c) 2022, 2019, 2017, 2015, 2014 by Stephen Thirlwall.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Log::Any::Plugin, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Any::Plugin
CPAN shell
perl -MCPAN -e shell install Log::Any::Plugin
For more information on module installation, please visit the detailed CPAN module installation guide.