Mojo::Log::Role::Format - Add sprintf logging to Mojo::Log
use Mojo::Log; my $log = Mojo::Log->new->with_roles('+Format')->level('debug'); # [info] cool beans $log->logf(info => 'cool %s', 'beans'); # [warn] serializing {"data":"structures"} $log->logf(warn => 'serializing %s', {data => 'structures'});
Mojo::Log::Role::Format is a Mojo::Log role which allow you to log with a format like sprintf(), avoid "Use of uninitialized" warnings and will also serialize data-structures and objects.
sprintf()
$cb = $log->logf_serialize; $log = $log->logf_serialize(sub (@args) { ... });
This attribute must hold a callback that will be used to serialize the arguments passed to "logf".
The default callback uses Data::Dumper with some modifications, but these settings are currently EXPERIMENTAL and subject to change:
$Data::Dumper::Indent = 0; $Data::Dumper::Maxdepth = $Data::Dumper::Maxdepth || 2; $Data::Dumper::Pair = ':'; $Data::Dumper::Quotekeys = 1; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Terse = 1; $Data::Dumper::Useqq = 1;
$log = $log->logf($level => $format, @args); $log = $log->logf($level => $message);
See "SYNOPSIS".
Jan Henning Thorsen
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
Mojo::Log
To install Mojo::Log::Role::Format, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Log::Role::Format
CPAN shell
perl -MCPAN -e shell install Mojo::Log::Role::Format
For more information on module installation, please visit the detailed CPAN module installation guide.