MooX::...Logger(3pm)
π MooX::Role::Logger β the MooX::...Logger(3pm) era π
okay bestie, listen up π this is the manpage for MooX::Role::Logger, and it's genuinely one of the most chill little Perl roles you'll ever meet. it's from the User Contributed Perl Documentation crew, and it's here to hand you logging powers without you having to care where the logs go. iconic behavior, honestly.
β¨ NAME β¨
MooX::Role::Logger β Provide logging via Log::Any π
πΈ VERSION πΈ
version 0.005 β yes, she's little, she's mighty, no cap.
π¦ SYNOPSIS π¦
So like, in your modules, you do this cute little thing:
package MyModule;
use Moose;
with 'MooX::Role::Logger';
sub run {
my ($self) = @_;
$self->cry;
}
sub cry {
my ($self) = @_;
$self->_logger->info("I'm sad");
}
and then in your application, you set up where all those feelings go:
use MyModule;
use Log::Any::Adapter ('File', '/path/to/file.log');
MyModule->run;
that's it. that's the whole vibe. π
π DESCRIPTION π
This role provides universal logging via Log::Any. The class using this role doesn't need to know or care about the details of log configuration, implementation or destination. like, it literally does not want to know. it's giving "not my job, bestie" π«Ά
Use it when you want your module to offer logging capabilities, but don't know who is going to use your module or what kind of logging they will implement. This role lets you do your part and leaves actual log setup and routing to someone else. so you bring the vibes, they bring the destination. delegation, but make it β¨architectureβ¨.
The application that ultimately uses your module can then choose to direct log messages somewhere based on its own needs and configuration with Log::Any::Adapter. their app, their rules, their log file. π
This role is based on Moo so it should work with either Moo or Moose based classes. equal opportunity logging. we love to see it. π
π USAGE π
π§ͺ Testing
Testing with Log::Any is pretty easy, thanks to Log::Any::Test. Just load that before Log::Any loads and your log messages get sent to a test adapter that includes testing methods. chef's kiss, no setup drama π₯
use Test::More 0.96;
use Log::Any::Test;
use Log::Any qw/$log/;
use lib 't/lib';
use MyModule;
MyModule->new->cry;
$log->contains_ok( qr/I'm sad/, "got log message" );
done_testing;
look at her. asserting on feelings. πβ¨
π Customizing
If you have a whole set of classes that should log with a single category, create your own role and set the "_build__logger_category" there. one category to rule them all:
package MyLibrary::Role::Logger;
use Moo::Role;
with 'MooX::Role::Logger';
sub _build__logger_category { "MyLibrary" }
Then in your other classes, use your custom role:
package MyLibrary::Foo;
use Moo;
with 'MyLibrary::Role::Logger'
boom. inherited the whole aesthetic. π¦
π METHODS π
πͺ΅ _logger
Returns a logging object. See Log::Any for a list of logging methods it accepts. it's the plug β whatever Log::Any can do, this thing can do. π
π·οΈ _build__logger_category
Override to set the category used for logging. Defaults to the class name of the object (which could be a subclass). You can override to lock it to a particular name:
sub _build__logger_category { __PACKAGE__ }
basically: "I want my logs labeled exactly like this, tyvm." π
π SEE ALSO π
Since MooX::Role::Logger is universal, you have to use it with one of several Log::Any::Adapter classes. pick your fighter:
Log::Any::Adapter::FileLog::Any::Adapter::StderrLog::Any::Adapter::StdoutLog::Any::Adapter::ScreenColoredLevelLog::Any::Adapter::DispatchLog::Any::Adapter::SyslogLog::Any::Adapter::Log4perl
These other logging roles are specific to particular logging packages, rather than being universal β the "I'm loyal to one framework" girlies:
MooseX::LazyLogDispatchMooseX::Log::Log4perlMooseX::LogDispatchMooseX::Role::LogHandlerMooseX::Role::Loggable(usesLog::Dispatchouli)Role::Log::Syslog::Fast
π SUPPORT π
π Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/MooX-Role-Logger/issues>. You will be notified automatically of any progress on your issue. so like, you'll get updates fr fr, no ghosting. π»π«
π¦ Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license.
<https://github.com/dagolden/MooX-Role-Logger>
git clone https://github.com/dagolden/MooX-Role-Logger.git
go on, clone her, she's cute π
π AUTHOR π
David Golden <dagolden@cpan.org> β the mastermind, the main character, the one who said "logging should just work" π
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
π and that's the whole page, bestie! perl v5.34.0, dated 2022-06-16, from the User Contributed Perl Documentation section β logging is literally your moment now, go be the main character of your own Log::Any adapter setup β¨π¦π
π¦ where this page comes from
- debian bookworm: libmoox-role-logger-perl 0.005-2 Β· Apache-2.0
- debian trixie: libmoox-role-logger-perl 0.005-2 Β· Apache-2.0
- ubuntu noble: libmoox-role-logger-perl 0.005-2 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms