Skip to content

LC-416 added json logging for elk #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lucille-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@
</exclusions>
</dependency>


<!-- dependency to allow json logging for log4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-layout-template-json</artifactId>
<version>2.22.1</version>
</dependency>

<dependency>
<groupId>org.apache.kafka</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* An operation that can be performed on a Document.<br>
Expand Down
10 changes: 9 additions & 1 deletion lucille-core/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
</Policies>
<DefaultRolloverStrategy max="4" />
</RollingFile>
<RollingFile name="file-json" fileName="./log/com.kmwllc.lucille-json.log" filePattern="./log/com.kmwllc.lucille-json-%i.log">
<JsonTemplateLayout eventTemplateUri="classpath:EcsLayout.json"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 KB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
</Appenders>
<Loggers>
<!-- NOTE: Replace the "file" AppenderRef with "file-json" if you would like to enable json logging. -->
<!-- You can also add an appender like '<AppenderRef ref="file-json" />' to the loggers to get both non-json AND json logging. -->
<Root level="INFO">
<AppenderRef ref="console" />
<AppenderRef ref="file" />
</Root>

<Logger name="com.kmwllc.lucille.core.Heartbeat" level="INFO" additivity="false">
<AppenderRef ref="heartbeat" />
</Logger>
Expand Down
49 changes: 49 additions & 0 deletions lucille-core/src/test/resources/EcsLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"@timestamp": {
"$resolver": "timestamp",
"pattern": {
"format": "yy/MM/dd'T'HH:mm:ss'Z'",
"timeZone": "UTC"
}
},
"ecs.version": "1.2.0",
"log.level": {
"$resolver": "level",
"field": "name"
},
"message": {
"$resolver": "message",
"stringified": true
},
"process.thread.name": {
"$resolver": "thread",
"field": "name"
},
"log.logger": {
"$resolver": "logger",
"field": "name"
},
"labels": {
"$resolver": "mdc",
"flatten": true,
"stringified": true
},
"tags": {
"$resolver": "ndc"
},
"error.type": {
"$resolver": "exception",
"field": "className"
},
"error.message": {
"$resolver": "exception",
"field": "message"
},
"error.stack_trace": {
"$resolver": "exception",
"field": "stackTrace",
"stackTrace": {
"stringified": true
}
}
}
Loading