maestr0
maestr0

Reputation: 5608

Will disabling Logback console appender increase performance if I log to file anyway?

Will disabling Logback console appender increase performance in any way if I use the FileAppender?

I use PlayFramework 2.3 with Logback as a logging framework. I have to store application logs in files which is relatively slow. Does it make sense to disable the standard console appender to increase the logging performance or would that be a premature optimization? Logger performance is not an issue for me even with the console logger enabled. I'm just curious if it would matter in this case.

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${application.home}/logs/application.log</file>
    <encoder>
        <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
    </encoder>
</appender>

DISABLE THIS APPENDER ???

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
    </encoder>
</appender>

Upvotes: 2

Views: 4542

Answers (2)

Fran&#231;ois Maturel
Fran&#231;ois Maturel

Reputation: 6162

You should indeed disable the console appender in production environment. As stated in this blog :

Java logging severely affects performance of your application. Its quite common sense that more you log, more you perform file IO which slows down your application.

You must then carefully choose the level of what you log in your production environment (prefer the WARN level).

And in the file appender also affects your performances, use the native asynchronous logback appender to be sure not to block your application threads:

<configuration>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>${application.home}/logs/application.log</file>
        <encoder>
            <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
        </encoder>
    </appender>

    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="FILE" />
    </appender>

    <root level="WARN">
        <appender-ref ref="ASYNC" />
    </root>
</configuration>

Upvotes: 5

user4695271
user4695271

Reputation:

It will definitely increase the performance, but "how much" is only measurable for you. Another point is, you should not be logging into console in higher environments, that's OK for DEV, but once you are in a different one it doesn't makes much sense since you can have several applications deployed in the same server and you will get flooded. In that case, logging to a file makes sense and it's the recommended way.

Hope this helps.

Upvotes: 0

Related Questions