Skip to content

Commit f30b723

Browse files
authored
Merge pull request #788 from rabbitmq/json-log
Add JSON log example
2 parents 3651c62 + 4aa9f56 commit f30b723

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

docs/examples/json-log/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# JSON Log Example
2+
3+
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.
4+
5+
Pull Requests:
6+
* [Switch from Lager to the new Erlang Logger API for logging #2861](https://github.com/rabbitmq/rabbitmq-server/pull/2861)
7+
* [Logging: Add configuration variables to set various formats #2927](https://github.com/rabbitmq/rabbitmq-server/pull/2927)
8+
9+
This example configures RabbitMQ to output JSON logs.
10+
11+
You can deploy this example like this:
12+
13+
```shell
14+
kubectl apply -f rabbitmq.yaml
15+
```
16+
17+
And once deployed, you can see the JSON logs:
18+
19+
```shell
20+
kubectl logs json-server-0 -c rabbitmq
21+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: rabbitmq.com/v1beta1
2+
kind: RabbitmqCluster
3+
metadata:
4+
name: json
5+
spec:
6+
# JSON logging is supported from RabbitMQ 3.9 onwards
7+
image: rabbitmq:3.9-management
8+
rabbitmq:
9+
# Disable RABBITMQ_LOGS=- which is set in
10+
# https://github.com/docker-library/rabbitmq/blob/ece63d4534cc44abd6b1ec35bbd9aa0d21e87e1d/3.9/ubuntu/Dockerfile#L211
11+
# Otherwise, this environment variable will override all log configurations in additionalConfig.
12+
envConfig: |
13+
RABBITMQ_LOGS=""
14+
# More log configuration options can be found in https://github.com/rabbitmq/rabbitmq-server/pull/2927
15+
additionalConfig: |
16+
log.console = true
17+
log.console.level = debug
18+
log.console.formatter = json
19+
log.console.formatter.json.field_map = level time msg domain file line pid
20+
log.console.formatter.time_format = rfc3339_T

docs/examples/json-log/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
kubectl logs json-server-0 -c rabbitmq --tail=3 | jq .

0 commit comments

Comments
 (0)