NAME

Log::Any::Plugin::Stringify - Custom argument stringification plugin for log adapters

VERSION

version 0.012

SYNOPSIS

# 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);

DESCRIPTION

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( ... ) );

CONFIGURATION

These configuration values are passed as key-value pairs: Log::Any::Plugin->add('Stringify', stringifier => \&my_func);

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.

separator => ''

See default_stringifier below for the default stringifier behaviour.

METHODS

There are no methods in this package which should be directly called by the user. Use Log::Any::Plugin->add() instead.

install

Private method called by Log::Any::Plugin->add()

default_stringifier

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.

SEE ALSO

Log::Any::Plugin

ACKNOWLEDGEMENTS

Thanks to Strategic Data for sponsoring the development of this module.

AUTHOR

Stephen Thirlwall <sdt@cpan.org>

COPYRIGHT AND LICENSE

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.