mp911de / logstash-gelf

Graylog Extended Log Format (GELF) implementation in Java for all major logging frameworks: log4j, log4j2, java.util.logging, logback, JBossAS7 and WildFly 8-12
http://logging.paluch.biz
MIT License
425 stars 102 forks source link

Spring Boot log4j2 initialization time #262

Closed gordor4 closed 3 years ago

gordor4 commented 3 years ago

Hello! I'm using log4j2 with xml config

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout
                    pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable"/>
        </Console>
        <Gelf name="gelf" host="tcp:xx.xx.xx.xx" port="12201" version="1.1" extractStackTrace="true"
              filterStackTrace="true" maximumMessageSize="8192"
              originHost="%host{fqdn}">
            <Field name="timestamp" pattern="%d{dd MMM yyyy HH:mm:ss,SSS}"/>
            <Field name="level" pattern="%level"/>
            <Field name="simpleClassName" pattern="%C{1}"/>
            <Field name="className" pattern="%C"/>
            <Field name="server" pattern="%host"/>
            <Field name="server.fqdn" pattern="%host{fqdn}"/>
        </Gelf>
    </Appenders>

    <Loggers>
        <Root level="info">
            <AppenderRef ref="gelf"/>
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

Application without gelf logging starting about 2 seconds, but with additional gelf appender more that 40 sec. Is this is normal start time or I can boost it?

gordor4 commented 3 years ago

if anyone face this problem too. Slows down getCanonicalHost name with IPv6 addresses. This is Java spoofing security process. For local development you can use JVM param -Djava.net.preferIPv4Stack=true

jklap commented 3 years ago

If you are running JDK 8 less than u113 there was a known JDK bug that also caused slow lookups. Adding an entry to /etc/hosts for your hostname and 127.0.0.1 fixes that issue

mp911de commented 3 years ago

The observed delay is very likely caused by the DNS reverse lookup. Check out https://logging.paluch.biz/hostname-lookup.html for options to provide the hostname through the environment.

gordor4 commented 3 years ago

The observed delay is very likely caused by the DNS reverse lookup. Check out https://logging.paluch.biz/hostname-lookup.html for options to provide the hostname through the environment.

Thanks