Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

While looking at Mastodon::Client I hoped it had logging so I could see what URL exactly it was hitting.

It does have logging, via Log::Any and here's the block I need:

if ($log->is_trace) { require Data::Dumper; $log->debugf('Method: %s', $method); $log->debugf('URL: %s', $url); $log->debugf('Headers: %s', Data::Dumper::Dumper( $headers )); $log->debugf('Data: %s', Data::Dumper::Dumper( $data )); }

So, where exactly is the log? Half an hour later I'm still baffled.

The documentation for Log::Any is a little obscure to me.

All I have to go on is my $log = Log::Any->get_logger( category => 'Mastodon' );

I'd appreciate help figuring out exactly how I'm meant to get log output onto my screen, or to a file? And how I set that is_trace to true so that it will be logged at all?

I suspect that if I knew more about Moo and Roles this would be more obvious to me?

Replies are listed 'Best First'.
Re: How does Log::Any actually … log?
by hippo (Archbishop) on Dec 18, 2022 at 12:48 UTC

    All you should need to do is to set up the log consumer in your script. eg.

    use strict; use warnings; use Mastodon::Client; use Log::Any::Adapter ('Stdout', log_level => 'trace');

    This should set up logging to STDOUT (since you asked for "get log output onto my screen") with level "trace" so that your call to is_trace will return true.

    While I do use Log::Any, I do not use Mastodon::Client so if that module is doing something quirky then you may need to dig a bit deeper.

    I suspect that if I knew more about Moo and Roles this would be more obvious to me?

    Those are unrelated concepts, so there's no need to worry about them just to get Log::Any to trace your code.


    🦛

      Oh that's made it much more clear, thank you. It's a framework, and I plug in different outputs using the Adapter so I can have different outputs in different contexts.

Re: How does Log::Any actually … log?
by Corion (Patriarch) on Dec 18, 2022 at 10:33 UTC

    It seems you are supposed to do it using Log::Any::Adapter, but I don't see any way within that module of specifying the logfile via an environment variable.

    Maybe you are supposed to supply the $log yourself, by following the Log::Any documentation?