Skip to content

Commit

Permalink
Add JSON log example
Browse files Browse the repository at this point in the history
  • Loading branch information
ansd committed Aug 3, 2021
1 parent 3651c62 commit 4aa9f56
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/examples/json-log/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# JSON Log Example

RabbitMQ 3.9 switched from [Lager](https://github.com/erlang-lager/lager) to the new Erlang [Logger API](https://erlang.org/doc/man/logger.html) supporting JSON-formatted messages.

Pull Requests:
* [Switch from Lager to the new Erlang Logger API for logging #2861](https://github.com/rabbitmq/rabbitmq-server/pull/2861)
* [Logging: Add configuration variables to set various formats #2927](https://github.com/rabbitmq/rabbitmq-server/pull/2927)

This example configures RabbitMQ to output JSON logs.

You can deploy this example like this:

```shell
kubectl apply -f rabbitmq.yaml
```

And once deployed, you can see the JSON logs:

```shell
kubectl logs json-server-0 -c rabbitmq
```
20 changes: 20 additions & 0 deletions docs/examples/json-log/rabbitmq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
name: json
spec:
# JSON logging is supported from RabbitMQ 3.9 onwards
image: rabbitmq:3.9-management
rabbitmq:
# Disable RABBITMQ_LOGS=- which is set in
# https://github.com/docker-library/rabbitmq/blob/ece63d4534cc44abd6b1ec35bbd9aa0d21e87e1d/3.9/ubuntu/Dockerfile#L211
# Otherwise, this environment variable will override all log configurations in additionalConfig.
envConfig: |
RABBITMQ_LOGS=""
# More log configuration options can be found in https://github.com/rabbitmq/rabbitmq-server/pull/2927
additionalConfig: |
log.console = true
log.console.level = debug
log.console.formatter = json
log.console.formatter.json.field_map = level time msg domain file line pid
log.console.formatter.time_format = rfc3339_T
5 changes: 5 additions & 0 deletions docs/examples/json-log/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -eo pipefail

kubectl logs json-server-0 -c rabbitmq --tail=3 | jq .

0 comments on commit 4aa9f56

Please sign in to comment.