You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by jingguo yao <ya...@gmail.com> on 2021/09/06 12:51:18 UTC

Why does Logger class provide a bunch of info methods beside the varargs mthod?

org.apache.logging.log4j.Logger has the following info method with the
message parameter count from 0 to 10.

void info(String message)
void info(String message, Object p0)
void info(String message, Object p0, Object p1)
...
void info(String message, Object p0, Object p1, Object p2, Object p3,
Object p4, Object p5, Object p6, Object p7, Object p8, Object p9)

And it also has the following varargs info method:

void info(String message, Object... params)

With all the above methods available, only if the message parameter count
is more than 10,  varargs info method will be used.

What is the reason to have all these info methods? Is it that varargs' has
a negative impact on performance?

Here is some discussion about varargs' performance on Stackoverflow:


   1. https://stackoverflow.com/a/63121156/431698
   2. https://stackoverflow.com/a/69074193/431698 (I posted this answer)


-- 
Jingguo

Re: Why does Logger class provide a bunch of info methods beside the varargs mthod?

Posted by Gary Gregory <ga...@gmail.com>.
When you call a var argument method, Java creates an array for your
arguments, which might be considered wasteful in some use cases (like in a
loop). Providing APIs with "unrolled" arguments avoids this creating and
filling this array.

Gary


On Mon, Sep 6, 2021, 08:51 jingguo yao <ya...@gmail.com> wrote:

> org.apache.logging.log4j.Logger has the following info method with the
> message parameter count from 0 to 10.
>
> void info(String message)
> void info(String message, Object p0)
> void info(String message, Object p0, Object p1)
> ...
> void info(String message, Object p0, Object p1, Object p2, Object p3,
> Object p4, Object p5, Object p6, Object p7, Object p8, Object p9)
>
> And it also has the following varargs info method:
>
> void info(String message, Object... params)
>
> With all the above methods available, only if the message parameter count
> is more than 10,  varargs info method will be used.
>
> What is the reason to have all these info methods? Is it that varargs' has
> a negative impact on performance?
>
> Here is some discussion about varargs' performance on Stackoverflow:
>
>
>    1. https://stackoverflow.com/a/63121156/431698
>    2. https://stackoverflow.com/a/69074193/431698 (I posted this answer)
>
>
> --
> Jingguo
>