Skip to content

Commit

Permalink
fix json logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Sep 26, 2024
1 parent 8ca1cfd commit c1340c3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: grafana/oats
ref: a89d11407f7cbc1d31a01796f7746eef48a871a8
ref: 4ad43adebb426c61b3cf47d51b6e1d14f56059b3
path: oats
- name: Set up Go
uses: actions/setup-go@v5
Expand Down
4 changes: 2 additions & 2 deletions examples/java/json-logging-ecs/k8s/collector-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data:
- targets: [ 'localhost:8888' ]
filelog/json-ecs:
include:
- /var/log/pods/*/dice/*.log
- /var/log/pods/*/*/*.log
include_file_path: true
operators:
- id: container-parser
Expand All @@ -31,7 +31,7 @@ data:
expr: 'body matches "\\{[^{}]*\\}" == true'
- id: json_parser
type: json_parser
on_error: drop # TODO use 'drop_quiet' once available:
on_error: drop_quiet
body: attributes.message
timestamp:
parse_from: attributes["@timestamp"]
Expand Down
10 changes: 5 additions & 5 deletions examples/java/json-logging-logback/k8s/collector-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data:
- targets: [ 'localhost:8888' ]
filelog/json-logback:
include:
- /var/log/pods/*/dice/*.log
- /var/log/pods/*/*/*.log
include_file_path: true
operators:
- id: container-parser
Expand All @@ -31,8 +31,8 @@ data:
expr: 'body matches "\\{[^{}]*\\}" == true'
- id: json_parser
type: json_parser
on_error: drop # TODO use 'drop_quiet' once available:
body: attributes.message
on_error: drop_quiet
body: attributes.formattedMessage
timestamp:
parse_from: attributes.timestamp
layout_type: 'epoch'
Expand Down Expand Up @@ -120,9 +120,9 @@ data:
- id: remove_context
type: remove
field: attributes.context
- id: remove_message
- id: remove_formattedMessage
type: remove
field: attributes.message
field: attributes.formattedMessage
- id: remove_logtag
type: remove
field: attributes.logtag
Expand Down
4 changes: 2 additions & 2 deletions examples/java/json-logging-logback/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>

<root level="INFO">
<appender-ref ref="stdout"/>
<appender-ref ref="CONSOLE_JSON"/>
</root>

<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<appender name="CONSOLE_JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.JsonEncoder">
<withFormattedMessage>true</withFormattedMessage>
<withMessage>false</withMessage>
Expand Down
5 changes: 3 additions & 2 deletions examples/java/json-logging-logback/oats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ input:
- path: /rolldice
expected:
logs:
- logql: '{service_name="dice"} |~ `.*Anonymous player is rolling the dice:.*`'
regexp: 'Anonymous player is rolling the dice: \d+' # uses formatted message
- logql: '{service_name="dice"} |~ `.*simulating an error.*`'
equals:
- 'Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: simulating an error] with root cause'
equals: 'Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: simulating an error] with root cause'
attributes:
deployment_environment: staging
exception_message: "simulating an error"
Expand Down
2 changes: 1 addition & 1 deletion examples/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>Hello World REST Service</name>

<properties>
<spring.version>3.1.2</spring.version>
<spring.version>3.3.4</spring.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
Expand Down

0 comments on commit c1340c3

Please sign in to comment.