Logging
Use structured logging
Section titled “Use structured logging”- Such as
slogin golang.
Exporting logs from docker to Loki
Section titled “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
Section titled “Fluent bit docker-compose.yaml” fluent-bit: image: grafana/fluent-bit-plugin-loki:latest container_name: fluent-bit environment: - LOKI_URL=http://loki:3100/loki/api/v1/push volumes: - ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf ports: - "24224:24224" - "24224:24224/udp" networks: - monitoringfluent-bit.conf
Section titled “fluent-bit.conf”[INPUT] Name forward Listen 0.0.0.0 Port 24224[Output] Name grafana-loki Match * Url ${LOKI_URL} RemoveKeys source Labels {job="fluent-bit"} LabelKeys container_name BatchWait 1s BatchSize 1001024 LineFormat json LogLevel infoIn the docker-compose for your application, add:
logging: driver: fluentd options: fluentd-address: ${FLUENT_BIT_ADDRESS}:24224