Skip to content

Conversation

@timtebeek
Copy link
Member

There's a related recipe CompleExceptionLogging that is separate and could instead convert these cases to logging the full stacktrace, but this PR specifically addresses an issue with ParameterizedLogging.

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Oct 17, 2025
@timtebeek timtebeek self-assigned this Oct 17, 2025
@timtebeek timtebeek added the bug Something isn't working label Oct 17, 2025
@timtebeek timtebeek merged commit 080d3e2 into main Oct 17, 2025
1 check passed
@timtebeek timtebeek deleted the preserve-throwables-tostring branch October 17, 2025 12:16
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Oct 17, 2025
@maikebertpsc
Copy link

Thanks for the quick fix!

But there might still be a problem:
SLF4J checks the last argument of a log method for being an instance of Throwable.
If that's true, it will always log the stack trace.

So even though you cast the exception, so the log method if Object parameter is called, it will afaik still log the stack trace.
See also https://www.slf4j.org/faq.html#paramException

Maybe the more proper fix would be to call toString on the exception instead of casting it?

mergify bot added a commit to robfrank/linklift that referenced this pull request Oct 30, 2025
…rom 3.16.0 to 3.17.0 [skip ci]

[//]: # (dependabot-start)
⚠️ \*\*Dependabot is rebasing this PR\*\* ⚠️
Rebasing might not happen immediately, so don't worry if this takes some time.
Note: if you make any changes to this PR yourself, they will take precedence over the rebase.
---
[//]: # (dependabot-end)
Bumps [org.openrewrite.recipe:rewrite-logging-frameworks](https://github.com/openrewrite/rewrite-logging-frameworks) from 3.16.0 to 3.17.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-logging-frameworks's releases](https://github.com/openrewrite/rewrite-logging-frameworks/releases).*

> 3.17.0
> ------
>
> What's Changed
> --------------
>
> * Cast `Throwables` to `Object` to preserve toString behavior in `ParameterizedLogging` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-logging-frameworks#258](https://redirect.github.com/openrewrite/rewrite-logging-frameworks/pull/258)
>
> **Full Changelog**: <openrewrite/rewrite-logging-frameworks@v3.16.0...v3.17.0>


Commits

* [`5a97f51`](openrewrite/rewrite-logging-frameworks@5a97f51) Fix recipe validation issues
* [`080d3e2`](openrewrite/rewrite-logging-frameworks@080d3e2) Cast `Throwables` to `Object` to preserve toString behavior in `Parameterized...
* See full diff in [compare view](openrewrite/rewrite-logging-frameworks@v3.16.0...v3.17.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-logging-frameworks&package-manager=maven&previous-version=3.16.0&new-version=3.17.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
Dependabot commands and options
  
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show  ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Recipe org.openrewrite.java.logging.slf4j.ParameterizedLogging corner case with exception object

3 participants