docker-compose.yml

Version: '3' services: # MongoDB: https://hub.docker.com/_/mongo/ mongo: image: mongo:4.2 networks: - # graylog Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docker.html Elasticsearch: Image: docker. Elastic. Co/elasticsearch/elasticsearch - oss: 7.10.2 environment: Host =0.0.0.0 -transport. host= localhost-network. host=0.0.0.0 -" ES_JAVA_OPTS= -xMS512m -XMx512m "ulimits: memlock: soft: -1 hard: -1 deploy: resources: limits: memory: 1g networks: - graylog # Graylog: https://hub.docker.com/r/graylog/graylog/ graylog: image: graylog/graylog: 4.1 the environment: # CHANGE ME (must be at least 16 characters)! - GRAYLOG_PASSWORD_SECRET=somepasswordpepper # Password: admin - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 - GRAYLOG_HTTP_EXTERNAL_URI = http://127.0.0.1:9000/ - GRAYLOG_ROOT_TIMEZONE = Asia/Shanghai entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 -- /docker-entrypoint.sh networks: - graylog restart: always depends_on: - mongo - elasticsearch ports: # Graylog web interface and REST API - 9000:9000 # Syslog TCP - 1514:1514 # Syslog UDP - 1514:1514/udp # GELF TCP - 12201:12201 # GELF UDP - 12201:12201/udp networks: graylog: driver: bridgeCopy the code

Use the docker-compose up command to start

Graylog configuration

http://192.168.9.3:9000

The default account password is admin

Click System -> Inputs

Search for UDP, select GELF UDP, and then click Launch New Input

Select "Global", "Title", and click "Save".

Project configuration

pom.xml

<dependency>
    <groupId>de.siegmar</groupId>
    <artifactId>logback-gelf</artifactId>
    <version>3.0.0</version>
</dependency>
Copy the code

logback.xml

GELF < appender name = "" class =" DE. Siegmar. Logbackgelf. GelfUdpAppender "> < graylogHost > 192.168.9.3 < / graylogHost > <graylogPort>12201</graylogPort> <maxChunkSize>508</maxChunkSize> <useCompression>true</useCompression> <messageIdSupplier class="de.siegmar.logbackgelf.MessageIdSupplier"/> <encoder class="de.siegmar.logbackgelf.GelfEncoder"> <! -- <originHost>localhost</originHost>--> <includeRawMessage>false</includeRawMessage> <includeMarker>true</includeMarker> <includeMdcData>true</includeMdcData> <includeCallerData>false</includeCallerData> <includeRootCauseData>false</includeRootCauseData> <includeLevelName>true</includeLevelName> <shortPatternLayout class="ch.qos.logback.classic.PatternLayout"> <pattern>%d - %m%nopex</pattern> </shortPatternLayout> <fullPatternLayout class="ch.qos.logback.classic.PatternLayout"> <pattern>%d - %m%n</pattern> </fullPatternLayout> <numbersAsString>false</numbersAsString> <staticField>app_name:graylog-test</staticField> <staticField>os_arch:${os.arch}</staticField> <staticField>os_name:${os.name}</staticField> <staticField>os_version:${os.version}</staticField> </encoder> </appender> <root level="info"> <appender-ref ref="GELF"/> </root>Copy the code

Start the project for testing.

See the log