Operations 7 min read

Deploying Graylog with Docker Compose and Integrating It into a Spring Boot Application

This guide explains how to set up Graylog for centralized log aggregation using Docker Compose, configure its inputs, and integrate it with a Spring Boot project via Logback GELF appender to enable searchable, centralized logging across microservice instances.

Architecture Digest
Architecture Digest
Architecture Digest
Deploying Graylog with Docker Compose and Integrating It into a Spring Boot Application

In microservice architectures, logs are scattered across multiple instances, making troubleshooting difficult; a log aggregation tool like Graylog centralizes logs.

First, deploy Graylog using a docker-compose.yml that defines services for Mongo, Elasticsearch, and Graylog, adjusting the external URI IP and port as needed.

version: '3'
services:
  mongo:
    image: mongo:4.2
    networks:
      - graylog
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
    environment:
      - http.host=0.0.0.0
      - transport.host=localhost
      - network.host=0.0.0.0
      - "ES_JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=true -Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    deploy:
      resources:
        limits:
          memory: 1g
    networks:
      - graylog
  graylog:
    image: graylog/graylog:4.2
    environment:
      - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
      - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
      - GRAYLOG_HTTP_EXTERNAL_URI=http://
YOUR_IP
:9009/
    entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 -- /docker-entrypoint.sh
    networks:
      - graylog
    restart: always
    depends_on:
      - mongo
      - elasticsearch
    ports:
      - 9009:9000
      - 1514:1514
      - 1514:1514/udp
      - 12201:12201
      - 12201:12201/udp
networks:
  graylog:
    driver: bridge

After starting the containers with docker-compose up -d , access the Graylog web UI (default credentials admin/admin) and create a GELF UDP input by providing a title and saving.

Next, integrate Graylog into a Spring Boot project by adding the logback-gelf dependency and configuring logback.xml with a GELF appender that points to the Graylog host and port.

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

<appender name="GELF" class="de.siegmar.logbackgelf.GelfUdpAppender">
  <!-- Graylog server address -->
  <graylogHost>YOUR_IP</graylogHost>
  <!-- UDP input port -->
  <graylogPort>12201</graylogPort>
  <maxChunkSize>508</maxChunkSize>
  <useCompression>true</useCompression>
  <encoder class="de.siegmar.logbackgelf.GelfEncoder">
    <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>%m%nopex</pattern>
    </shortPatternLayout>
    <fullPatternLayout class="ch.qos.logback.classic.PatternLayout">
      <pattern>%d - [%thread] %-5level %logger{35} - %msg%n</pattern>
    </fullPatternLayout>
    <staticField>app_name:austin</staticField>
  </encoder>
</appender>

Replace the placeholder IP with your Graylog server address, run the Spring Boot application, and you will see its logs appear in Graylog’s search interface, where you can query using simple keyword searches or advanced expressions.

DockerLoggingSpring Bootlog managementDocker ComposeGraylogGELF
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.