log4perl icon indicating copy to clipboard operation
log4perl copied to clipboard

parameterized logging?

Open burak opened this issue 1 year ago • 1 comments

Hi,

Short summary:

Instead of

DEBUG "Got here with " . $foo;

or even

DEBUG "Got here with " . Dumper $foo;

or even

DEBUG sprintf "Got here with %s", Dumper $foo;

It might be nicer to have a

DEBUG "Got here with {} and then {} and even {}", $foo, $bar, $baz;

This is actually a slf4j feature, but I think that it is quite a handy functionality to have (scroll down in the linked doc).

https://www.slf4j.org/faq.html#logging_performance

Implementation details:

https://github.com/qos-ch/slf4j/blob/master/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java

The functionality boils down to replacing "{}" with the parameter list. It is akin to sprintf "%s" and for the reference parameters, Data::Dumper can be utilized as well.

burak avatar May 09 '24 21:05 burak

Do you know Log::Any? It is a log producer that can be bound to Log::Log4perl using Log::Any::Adapter::Log4perl.

Logging

There are also versions of each of the logging methods with an additional "f" suffix (infof, errorf, debugf, etc.) that format a list of arguments.

XSven avatar May 22 '24 12:05 XSven