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

I am using Log::Dispatch in an application. I can control the level of log messages by changing the level option in the constructor of the dispatcher option. I am reading this value from an external file, so I don't have to touch the code to change logging level.

Is there a way to configure Log::Dispatcher so it will only print log messages from within a given module or even from within a specific method? Better yet to set log level on calls starting from specific places?

e.g. my configuration file would look something like this:

[logger] default=critical My::Frobnic=debug My::Frobnic::DBI::setup=debug
meaning that if the debug message was sent from within the My::Frobnic module or from within the My::Frobnic::DBI::setup method I'd like to have 'debug' level logging while in all other places 'critical' level only.

Update
link updated, I was talking about Log::Dispatch, thanks to rinceWind

Replies are listed 'Best First'.
Re: logging only calls within a module
by rhesa (Vicar) on Dec 05, 2006 at 16:10 UTC
    You can use the callbacks argument to the Log::Dispatch constructor:
    my $logger = Log::Dispatch->new( ..., callbacks => \&package_filter, ); sub package_filter { my %message = @_; my ( $pkg, $file, $line ) = caller(3); # please check that 3 is th +e correct level for your situation # decide if the package $pkg should be logged if( should_log( $pkg ) ) { return $message{'message'}; } # otherwise, suppress this message return; }
    Note that you can also pass an arrayref of callback functions to the Log::Dispatch constructor. They will be called in the specified order.
      Yes, that's good though currently that is caller(6).

      The problem is only that I will need to be sure this is the correct number. I think I'll ask Dave if he would be ready to provide a method that would return this number. That way in case he changes something in the implementation I can still have the correct number.