Reputation: 16865
Normally when using dancer you call, for example
debug 'foo';
and it will log the text. But I want to be able to log stuff in an object that doesn't import the dancer syntax. I'm wondering if there's a way to get dancer to just hand me it's log object (I assume there is one) so that I can call things like debug using an object syntax, e.g.
$logger->debug( 'foo' );
Upvotes: 9
Views: 1264
Reputation: 508
I'm not sure I follow what you want to do, if you want a logger "that has nothing to do with Dancer" why do you want the one Dancer provides?
You can of course create an instance of a Dancer::Logger::Whatever class but then, I don't really see the point.
Why not using a real standalone logger like Log::Dispatchouli for instance?
Upvotes: 0
Reputation: 726
You can import just the debug keyword.
use Dancer qw(:syntax debug);
debug 'foo';
This way the rest of the functions won't pollute your namespace, but you will still have the familiar DSL syntax. See https://metacpan.org/module/Dancer#EXPORTS for more info.
Upvotes: 0
Reputation: 21
use Dancer::Logger::Console;
my $logger = Dancer::Logger::Console->new;
$logger->debug("Perl Dancer Rocks!");
You can replace the Console
logger with any other logger you want such as Syslog or ConsoleAggregator
Upvotes: 2