This topic has come up several times, although your request seems slightly
different.
Every log event in Log4j 2 is handled by a message object. When you specify
logger.debug("", p1, p2) that gets converted essentially to logger.debug(new
ParameterizedMessage("", p1, p2)); . So if you want to use a different message
format you could create a JavaStringMessage and just do logger.debug(new
JavaStringMessage("", p2, p2));
Most proposals to date have asked to use String.format for the whole String
while you seem to be suggesting that each item within {} be replaced by
whatever String.format returns from the single parameter passed to it. I would
think that would be slower than handling the whole String.
Ceki has tested java.text.MessageFormat and said that it is at least 10 times
slower than the way ParameterizedMessage work. I don't know if he, or anyone
else, has compared Formatter or String.format against ParameterizedMessage but
I'd find it hard to believe it isn't considerably slower also. That said, if
someone wants to implement it I have no problem adding it. If it is
demonstrated to be nearly the same speed I would also have no problem making it
the default.
Ralph
On Aug 9, 2012, at 1:26 PM, Paul Benedict wrote:
> Forgive me if this feature already exists, but I was hoping to find if
> log4j 2 contained a way to configure the format *provider* of
> parametrized messages. This is an important aspect for my own work
> because I have some sophisticated formatting in my logs that use
> String.format() [1] -- especially for floating point values like
> currency.
>
> Rather than:
> logger.debug("Logging in user {} with id {}", user.getName(), user.getId());
>
> I would like some more complexity like:
> logger.debug("Logging in user {%s} with id {%10s}", user.getName(),
> user.getId());
>
> I am eager to hear any opinions on my proposed feature.
>
> [1]
> http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax
>
> Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]