in reply to Turning off logging

Hi, you missed one very important part of the doc for Log::Any::Adapter::File:

"Category is ignored."

Also, note that the consumers of your log statements decide what they will consume by setting the log level, as well as the category (assuming the adapter they choose to use supports filtering by log level). So specifying a log level when defining the logger attribute of your object will have no effect: all you can control as the producer is the level of the message. Here's a simple demonstration:

Module:

package MyClass; use Log::Any (); use Moo; has log => ( is => 'ro', default => sub { Log::Any->get_logger(category => 'unfolder') }, ); sub greet { $_[0]->log->debug('HELO, WORLD'); }; 1; __END__
Script:
# 1224985.pl use strict; use warnings; use feature 'say'; use lib '.'; use MyClass; use Log::Any::Adapter; my $level = shift or die 'log level must be provided'; my $obj = MyClass->new; Log::Any::Adapter->set('Stdout', log_level => $level); say '>'; $obj->greet; say '<'; __END__
Tests:
$ perl 1224985.pl critical > < $ perl 1224985.pl debug > HELO, WORLD <

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Turning off logging
by frazap (Monk) on Nov 05, 2018 at 14:39 UTC

    Thanks !

    I tried to use level:

    in my module

    $self->log-trace("this is useful for every users"): ... $self->log->debug("this is only useful during development");
    In a file using this module
    use Log::Any::Adapter( 'File', './log.txt', 'log_level'=>'trace' );

    Strange is that I still get the debug info in the file...

    How can I get only message send with trace ?

    Am I understanging the levels in the wrong direction ?

    Sorry, bare with me.

    Thanks

    F.
      Am I understanging the levels in the wrong direction ?

      I'm afraid so: trace is more verbose than debug. Switch them round and you should be good to go.