Skip to content

Configure logback to always log exception messages in a specific field#495

Merged
rob93c merged 1 commit intomainfrom
always-log-exception-messages
Apr 27, 2026
Merged

Configure logback to always log exception messages in a specific field#495
rob93c merged 1 commit intomainfrom
always-log-exception-messages

Conversation

@rob93c
Copy link
Copy Markdown
Member

@rob93c rob93c commented Apr 27, 2026

Summary by CodeRabbit

  • Refactor
    • Simplified exception handling and error logging infrastructure.
    • Optimised structured logging configuration for exception messages.

@rob93c rob93c requested a review from MartelliEnrico April 27, 2026 14:47
@rob93c rob93c self-assigned this Apr 27, 2026
@rob93c rob93c added enhancement New feature or request logs This marks changes revolving around logs labels Apr 27, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

The pull request simplifies exception logging by removing the explicit use of the EXCEPTION_MESSAGE_LOG_KEY structured logging constant from the exception handler and delegating exception message capture to Logback's throwableMessage provider in the JSON encoder configuration.

Changes

Cohort / File(s) Summary
Exception Handling Simplification
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
Simplifies the onException implementation by collapsing the multi-call fluent logger chain into a single invocation, removing structured logging of exception messages via the now-deleted EXCEPTION_MESSAGE_LOG_KEY.
Structured Logger API Update
src/main/java/com/github/stickerifier/stickerify/logger/StructuredLogger.java
Removes the EXCEPTION_MESSAGE_LOG_KEY public constant, eliminating its availability to external code whilst retaining all other logging context functionality.
Logback Configuration
src/main/resources/logback.xml
Adds a throwableMessage provider to the JSON encoder's provider list to automatically capture exception message content under the exception_message field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Stickerifier/Stickerify #489: Introduced the structured logging infrastructure and the EXCEPTION_MESSAGE_LOG_KEY that is now being removed in this PR.
  • Stickerifier/Stickerify #492: Added usage of EXCEPTION_MESSAGE_LOG_KEY within exception logging, which this PR simplifies by removing that key.

Suggested reviewers

  • MartelliEnrico

Poem

🐰 A logger's tale of cleanup true,
Exception keys we bid adieu,
With Logback's hand, the message flows,
Simpler paths where function goes!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change: configuring logback to log exception messages in a specific field, which aligns with the addition of the throwableMessage provider to logback.xml and the removal of manual exception message logging.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/resources/logback.xml`:
- Around line 18-20: The logback config uses an invalid JsonProvider element
`<throwableMessage>` inside the LoggingEventCompositeJsonEncoder setup; remove
the `<throwableMessage>` block so only supported providers remain (e.g., keep
`<stackTrace/>` which already emits exception text), ensuring the encoder
configuration only contains valid providers for logstash-logback-encoder 9.0;
verify the encoder element `LoggingEventCompositeJsonEncoder` and existing
`stackTrace` provider are left intact and no other custom provider references
the removed `<throwableMessage>`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e432bd2e-a71d-490e-a96e-20544a9b6dda

📥 Commits

Reviewing files that changed from the base of the PR and between 398146b and 9a906e0.

📒 Files selected for processing (3)
  • src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
  • src/main/java/com/github/stickerifier/stickerify/logger/StructuredLogger.java
  • src/main/resources/logback.xml
💤 Files with no reviewable changes (1)
  • src/main/java/com/github/stickerifier/stickerify/logger/StructuredLogger.java

Comment thread src/main/resources/logback.xml
Copy link
Copy Markdown
Contributor

@MartelliEnrico MartelliEnrico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rob93c rob93c merged commit 3baa2fb into main Apr 27, 2026
8 checks passed
@rob93c rob93c deleted the always-log-exception-messages branch April 27, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request logs This marks changes revolving around logs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants