Skip to content

Logging

Use structured logging

  • Such as slog in golang.

Exporting logs from docker to Loki

There are many options. One option is to use the fluent-bit plugin to export logs to Loki.

Fluent bit docker-compose.yaml

1
fluent-bit:
2
image: grafana/fluent-bit-plugin-loki:latest
3
container_name: fluent-bit
4
environment:
5
- LOKI_URL=http://loki:3100/loki/api/v1/push
6
volumes:
7
- ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
8
ports:
9
- "24224:24224"
10
- "24224:24224/udp"
11
networks:
12
- monitoring

fluent-bit.conf

1
[INPUT]
2
Name forward
3
Listen 0.0.0.0
4
Port 24224
5
[Output]
6
Name grafana-loki
7
Match *
8
Url ${LOKI_URL}
9
RemoveKeys source
10
Labels {job="fluent-bit"}
11
LabelKeys container_name
12
BatchWait 1s
13
BatchSize 1001024
14
LineFormat json
15
LogLevel info

In the docker-compose for your application, add:

1
logging:
2
driver: fluentd
3
options:
4
fluentd-address: ${FLUENT_BIT_ADDRESS}:24224