-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add good canonized logging setup for log4j and layouts
currently only bound in test Signed-off-by: Kevin O'Donnell <kevin@blockchaintp.com>
- Loading branch information
1 parent
b305b4f
commit 723d257
Showing
3 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"mdc": { | ||
"$resolver": "mdc" | ||
}, | ||
"exception": { | ||
"exception_class": { | ||
"$resolver": "exception", | ||
"field": "className" | ||
}, | ||
"exception_message": { | ||
"$resolver": "exception", | ||
"field": "message" | ||
}, | ||
"stacktrace": { | ||
"$resolver": "exception", | ||
"field": "stackTrace", | ||
"stackTrace": { | ||
"stringified": true | ||
} | ||
} | ||
}, | ||
"line_number": { | ||
"$resolver": "source", | ||
"field": "lineNumber" | ||
}, | ||
"class": { | ||
"$resolver": "source", | ||
"field": "className" | ||
}, | ||
"@version": 1, | ||
"source_host": "${hostName}", | ||
"message": { | ||
"$resolver": "message", | ||
"stringified": true | ||
}, | ||
"thread_name": { | ||
"$resolver": "thread", | ||
"field": "name" | ||
}, | ||
"@timestamp": { | ||
"$resolver": "timestamp" | ||
}, | ||
"level": { | ||
"$resolver": "level", | ||
"field": "name" | ||
}, | ||
"file": { | ||
"$resolver": "source", | ||
"field": "fileName" | ||
}, | ||
"method": { | ||
"$resolver": "source", | ||
"field": "methodName" | ||
}, | ||
"logger_name": { | ||
"$resolver": "logger", | ||
"field": "name" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Configuration: | ||
# Initial log level after loading configuration | ||
status: info | ||
name: TEST | ||
monitorInterval: 30 | ||
Properties: | ||
Appenders: | ||
File: | ||
# logging to a file for testing where a complete human readable, and detail level log is required | ||
- name: TEST_FILE | ||
fileName: target/test.log | ||
PatternLayout: | ||
# level, date and time, thread, full class name and line number, message | ||
pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%C{10}:%L] - %msg%n" | ||
# logging to a file for testing where a complete and detailed but not easily readable, log is required | ||
- name: TEST_JSON_FILE | ||
fileName: target/test-json.log | ||
JsonTemplateLayout: | ||
eventTemplateUri: classpath:log4j-json-layout.json | ||
Console: | ||
# For console logging during normal runs where detailed info about the code | ||
# is not desirable (no performance impact) | ||
- name: CONSOLE | ||
target: SYSTEM_OUT | ||
PatternLayout: | ||
# Level, thread, simple logger name, message | ||
pattern: "[%-5level] [%t] [%c{1}] - %msg%n" | ||
# For console logging while testing where timestamps are not needed | ||
# but detail about the code are (performance impact) | ||
- name: TEST_CONSOLE | ||
target: SYSTEM_OUT | ||
PatternLayout: | ||
# level, class shortname, line number, message | ||
pattern: "[%-5level] [%C{1}:%L] - %msg%n" | ||
# For logging json to a console, such as in a container | ||
- name: JSON_CONSOLE | ||
target: SYSTEM_OUT | ||
JsonTemplateLayout: | ||
eventTemplateUri: classpath:log4j-json-layout.json | ||
Loggers: | ||
Root: | ||
# Items not otherwise classified are recorded in test logs for forensics | ||
level: info | ||
AppenderRef: | ||
- ref: TEST_FILE | ||
- ref: TEST_JSON_FILE | ||
Logger: | ||
# Log what we are interested in at the root and the console | ||
- name: com.blockchaintp | ||
level: debug | ||
AppenderRef: | ||
- ref: TEST_CONSOLE |