-
-
Notifications
You must be signed in to change notification settings - Fork 16
Use structured logging #489
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
Open
rob93c
wants to merge
12
commits into
main
Choose a base branch
from
use-structured-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6f95d49
Add logstash logback encoder dependency
rob93c a77a568
Configure structured logging
rob93c 1eaae5d
Remove old log configuration and classes
rob93c 28b2e14
Use ScopedValue to pass userId information in logs
rob93c b467d64
Make logger method generic
rob93c 888a05b
Extract logging logic to record
rob93c c78195a
Refactor conversion logic to use mime type scoped value
rob93c 730e80d
Remove logger from test class
rob93c a2aae5c
Enrich logged context information
rob93c 3d5eb1e
Prevent bot answers when the message would be undeliverable
rob93c 61ccd95
Fix missing mime type in happy path log
rob93c 515d2ec
Improve failure logs
rob93c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
40 changes: 0 additions & 40 deletions
40
src/main/java/com/github/stickerifier/stickerify/logger/ExceptionHighlighter.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/main/java/com/github/stickerifier/stickerify/logger/HighlightHelper.java
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
src/main/java/com/github/stickerifier/stickerify/logger/MessageHighlighter.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/stickerifier/stickerify/logger/StructuredLogger.java
This file contains hidden or 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,36 @@ | ||
| package com.github.stickerifier.stickerify.logger; | ||
|
|
||
| import com.github.stickerifier.stickerify.telegram.model.TelegramRequest.RequestDetails; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.slf4j.event.Level; | ||
| import org.slf4j.spi.LoggingEventBuilder; | ||
|
|
||
| public record StructuredLogger(Logger logger) { | ||
|
|
||
| public static final ScopedValue<RequestDetails> REQUEST_DETAILS = ScopedValue.newInstance(); | ||
| public static final ScopedValue<String> MIME_TYPE = ScopedValue.newInstance(); | ||
|
|
||
| public StructuredLogger(Class<?> clazz) { | ||
| this(LoggerFactory.getLogger(clazz)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a {@link LoggingEventBuilder} at the specified level with request details and MIME type information, if set. | ||
| * | ||
| * @param level the level of the log | ||
| * @return the log builder with context information | ||
| */ | ||
| public LoggingEventBuilder at(Level level) { | ||
| var logBuilder = logger.atLevel(level); | ||
|
|
||
| if (REQUEST_DETAILS.isBound()) { | ||
| logBuilder = logBuilder.addKeyValue("request_details", REQUEST_DETAILS.get()); | ||
| } | ||
| if (MIME_TYPE.isBound()) { | ||
| logBuilder = logBuilder.addKeyValue("mime_type", MIME_TYPE.get()); | ||
| } | ||
|
|
||
| return logBuilder; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.