9

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' );
xenoterracide
  • 13,850
  • 17
  • 89
  • 196

3 Answers3

2
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

0

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?

sukria
  • 558
  • 2
  • 10
0

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.

Naveed
  • 706
  • 1
  • 5
  • 12
  • this still ties objects which may have nothing to do with dancer to dancer. My object should be able to work in catalyst, dancer, mojo, etc. – xenoterracide Mar 25 '12 at 00:26
  • I'm not sure what you mean by it "ties objects". It does not tie any objects to anything AFAIK. The ':syntax' option turns off all the Dancer magic, except for loading the config. – Naveed Mar 25 '12 at 23:24
  • but I don't need the dancer config... the object I'm writing doesn't necessarily need the dancer logger, it needs a logger, and currently it'd be getting used with dancer so it makes sense to pass it the dancer logger. by doing `use Dancer ...` my module becomes dependent upon dancer directly. – xenoterracide Mar 27 '12 at 17:42