Mojolicious::Plugin::Logf - Plugin for logging datastructures using sprintf
0.04
Mojolicious::Plugin::Logf is a plugin which will log complex datastructures and avoid "unitialized" warnings. This plugin use Mojo::Log or whatever "log" in Mojo is set to, to do the actual logging.
use Mojolicious::Lite; plugin "Logf"; get "/" => sub { my $self = shift; $self->logf(info => 'request: %s', $self->req->params->to_hash); };
$self = $c->logf; $c = $c->logf($level => $format, @args);
Logs a string formatted by the usual printf conventions of the C library function sprintf. $level need to be a valid Mojo::Log level. @args will be converted using "flatten".
printf
sprintf
$level
@args
Calling this method without any arguments will return $self (an instance of this plugin), allowing you to call "flatten":
$self
@args_as_strings = $c->logf->flatten(@args);
@args_as_strings = $self->flatten(@args);
Used to convert input @args using these rules:
Scalar
No rule applied.
Object with string overloading
Will be coverted to a string using the string overloading function.
Data structure or object
Will be serialized using Data::Dumper with these settings:
$Data::Dumper::Indent = 0; $Data::Dumper::Maxdepth = $Data::Dumper::Maxdepth || 2; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Terse = 1;
NOTE! These settings might change, but will always do its best to serialize the object into one line. $Data::Dumper::Maxdepth is used to avoid dumping large nested objects. Set this variable if you need deeper logging. Example:
$Data::Dumper::Maxdepth
local $Data::Dumper::Maxdepth = 1000; $c->logf(info => 'Deep structure: %s', $some_object);
Undefined value
Will be logged as "__UNDEF__".
Will register the "logf" helper in the application
Copyright (C) 2014, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mojolicious::Plugin::Logf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::Logf
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::Logf
For more information on module installation, please visit the detailed CPAN module installation guide.