title: How to send log by Log4j2 to Graylog?
body: <p><strong>I'm trying to integrate a java application with a graylog server on the docker. but I'm not able to send messages from my application to graylog, can someone help me?</strong></p>
  <p>Here is my <strong>Docker Run</strong>:</p>
  <pre><code>$ docker run --name mongo -d mongo:3
  $ docker run --name elasticsearch \
      -e &quot;http.host=0.0.0.0&quot; \
      -e &quot;ES_JAVA_OPTS=-Xms512m -Xmx512m&quot; \
      -d docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
  $ docker run --name graylog --link mongo --link elasticsearch \
      -p 9000:9000 -p 12201:12201 -p 1514:1514 \
      -e GRAYLOG_HTTP_EXTERNAL_URI=&quot;http://127.0.0.1:9000/&quot; \
      -d graylog/graylog:3.3
  </code></pre>
  <p>here is my Input config inside <strong>Graylog</strong></p>
  <p><a href="https://i.stack.imgur.com/e6fH2.png" rel="nofollow noreferrer">Graylog Input</a></p>
  <p>here is the <strong>application</strong> tutorial i am using:
  <a href="https://talhature.com/2020/04/25/using-graylog-with-log4j2/" rel="nofollow noreferrer">https://talhature.com/2020/04/25/using-graylog-with-log4j2/</a></p>
  <p>here is my <strong>log4j2.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
  &lt;Configuration status=&quot;TRACE&quot; monitorInterval=&quot;180&quot;&gt;
      &lt;Properties&gt;
          &lt;Property name=&quot;app-name&quot;&gt;graylog-example-fatjar&lt;/Property&gt;
  
          &lt;!-- CHANGE log-path ACCORDING TO YOUR NEEDS --&gt;
          &lt;Property name=&quot;log-path&quot;&gt;$${sys:application-directory}/${app-name}/log
          &lt;/Property&gt;
          &lt;Property name=&quot;log-pattern&quot;&gt;[%sn] %d{yyyy/MM/dd HH:mm:ss,SSS} [%-6p] [%t]
              %c{3}:%L - %m%n&lt;/Property&gt;
      &lt;/Properties&gt;
  
      &lt;!-- CHANGE HOST AND PORT PROPERTIES ACCORDING TO YOUR NEEDS --&gt;
      &lt;Appenders&gt;
          &lt;Gelf name=&quot;gelf&quot; host=&quot;udp:127.0.0.1&quot; port=&quot;12201&quot;
              version=&quot;1.1&quot; extractStackTrace=&quot;true&quot; filterStackTrace=&quot;true&quot;
              mdcProfiling=&quot;true&quot; includeFullMdc=&quot;true&quot; maximumMessageSize=&quot;8192&quot;
              originHost=&quot;%host{fqdn}&quot;&gt;
  
              &lt;!-- THESE FIELD DEFINITIONS ARE NOT MANDATORY, YOU CAN USE DEFAULTS --&gt;
              &lt;Field name=&quot;timestamp&quot; pattern=&quot;%d{dd MMM yyyy HH:mm:ss,SSS}&quot; /&gt;
              &lt;Field name=&quot;level&quot; pattern=&quot;%level&quot; /&gt;
              &lt;Field name=&quot;simpleClassName&quot; pattern=&quot;%C{1}&quot; /&gt;
              &lt;Field name=&quot;className&quot; pattern=&quot;%C&quot; /&gt;
              &lt;Field name=&quot;server&quot; pattern=&quot;%host&quot; /&gt;
              &lt;Field name=&quot;server.fqdn&quot; pattern=&quot;%host{fqdn}&quot; /&gt;
  
              &lt;!-- THESE ARE MY CUSTOM GRAYLOG FIELDS --&gt;
              &lt;Field name=&quot;logStream&quot; literal=&quot;MYAWESOMEAPPS&quot; /&gt;
              &lt;Field name=&quot;projectName&quot; literal=&quot;MYAWESOMEPROJECT&quot; /&gt;
          &lt;/Gelf&gt;
          &lt;RollingFile name=&quot;RollingFile&quot;
              fileName=&quot;${log-path}/server/${app-name}-server&quot;
              filePattern=&quot;${log-path}/server/${app-name}-server-%d{yyyy-MM-dd}-%i.log.gz&quot;
              append=&quot;false&quot;&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;${log-pattern}&lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;SizeBasedTriggeringPolicy size=&quot;100 MB&quot; /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
      &lt;/Appenders&gt;
  
      &lt;Loggers&gt;
          &lt;Root level=&quot;INFO&quot; additivity=&quot;false&quot; includeLocation=&quot;true&quot;&gt;
              &lt;AppenderRef ref=&quot;RollingFile&quot; /&gt;
              &lt;AppenderRef ref=&quot;gelf&quot; /&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  
  </code></pre>
  <p>*<em><strong>SOLUTION</strong></em></p>
  <p>up my docker this way to open a port 5555:</p>
  <pre><code>$ docker run --link mongo --link elasticsearch \
      -p 9000:9000 -p 12201:12201 -p 1514:1514 -p 5555:5555 \
      -e GRAYLOG_HTTP_EXTERNAL_URI=&quot;http://127.0.0.1:9000/&quot; \
      -d graylog/graylog:3.3
  </code></pre>
  <p>in my log4j2.xml i change the line 7:</p>
  <pre><code>&lt;Gelf name=&quot;Gelf&quot; host=&quot;tcp:127.0.0.1&quot; port=&quot;5555&quot; version=&quot;1.1&quot;
  </code></pre>
  <p>and my Graylog Input (Gelf:TCP):
  <a href="https://i.stack.imgur.com/aN6gE.png" rel="nofollow noreferrer">Graylog Input Gelf TCP</a></p>