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:latest3 container_name: fluent-bit4 environment:5 - LOKI_URL=http://loki:3100/loki/api/v1/push6 volumes:7 - ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf8 ports:9 - "24224:24224"10 - "24224:24224/udp"11 networks:12 - monitoring
fluent-bit.conf
1[INPUT]2 Name forward3 Listen 0.0.0.04 Port 242245[Output]6 Name grafana-loki7 Match *8 Url ${LOKI_URL}9 RemoveKeys source10 Labels {job="fluent-bit"}11 LabelKeys container_name12 BatchWait 1s13 BatchSize 100102414 LineFormat json15 LogLevel info
In the docker-compose for your application, add:
1 logging:2 driver: fluentd3 options:4 fluentd-address: ${FLUENT_BIT_ADDRESS}:24224