Skip to content
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

Avoid Commons Logging API for using LoggingCacheErrorHandler with a custom logger #28678

Merged

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Jun 22, 2022

At present, creating LoggingCacheErrorHandler with custom logger requires use of Commons Logging API, as the appropriate constructor expects org.apache.commons.logging.Log instance. As Commons Logging is rarely the logging framework of choice in applications these days, interaction with its API might not be desirable.

This commit adds LoggingCacheErrorHandler constructor that accepts logger name and thus avoids leaking out any details about the underlying logging framework, while also deprecating the existing constructor that accepts org.apache.commons.logging.Log.


I'm opening this PR to discuss one aspect of #28648 that was overlooked as that PR was superseded:

The first commit could maybe be update to deprecate the existing constructor that takes org.apache.commons.logging.Log and replace it with the one that takes String representing logger name as that way Commons Logging dependency wouldn't leak out at all. But I'd leave that decision to whoever reviews this PR.

These days, it's almost inevitable to have several logging frameworks on the classpath, with only one of those being the intended application-wide logging API. To avoid unintended use of other logging APIs, something like Checkstyle can be used to prohibit imports of undesirable classes. However, LoggingCacheErrorHandler makes this a bit difficult at the moment hence this proposal.

If you agree this proposal and also with the deprecation of constructor that uses org.apache.commons.logging.Log, I'll rework the tests to avoid use of deprecated constructor.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 22, 2022
@vpavic
Copy link
Contributor Author

vpavic commented Oct 19, 2022

Could you consider this change for 6.0?

I'd like to be able to set up LoggingCacheErrorHandler with a custom logger, but without being forced to use org.apache.commons.logging.Log.

Thanks.

@jhoeller
Copy link
Contributor

jhoeller commented Oct 19, 2022

Good point, we seem to have missed that part the first time around in the 5.3.22 revision.

I don't see a real need to deprecate the existing constructor (since we allow direct Log passing in other places as well) but we could easily add an alternative LoggingCacheErrorHandler(String loggerName, boolean logStackTraces) constructor for your scenario, avoiding Commons Logging API references in user code when specifying a custom logging category.

Drafting this locally, it is straightforward enough for a backport to 5.3.24, so I'm inclined to commit it there and repurpose this ticket for that addition to 5.3.x? Otherwise I can also create a separate GitHub issue for it.

@vpavic
Copy link
Contributor Author

vpavic commented Oct 19, 2022

Thanks for the feedback Juergen.

Not deprecating the constructor that accepts org.apache.commons.logging.Log is fine with me, I simply assumed once there's one that accepts the String, it would be preferred. Also great if you can make this a part of 5.3.

I can update the PR to remove the deprecation if that's your preference, and add some tests that use the new constructor.

@jhoeller
Copy link
Contributor

@vpavic If you could remove the deprecation and ideally rebase the PR onto 5.3.x (with a @since 5.3.24 label), I'd merge it there right away!

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 19, 2022
@jhoeller jhoeller added this to the 5.3.24 milestone Oct 19, 2022
@jhoeller jhoeller changed the title Avoid use of Commons Logging in LoggingCacheErrorHandler public API Avoid Commons Logging API for using LoggingCacheErrorHandler with a custom logger Oct 19, 2022
At present, creating LoggingCacheErrorHandler with custom logger requires use of Commons Logging API, as the appropriate constructor expects org.apache.commons.logging.Log instance. As Commons Logging is rarely the logging framework of choice in applications these days, interaction with its API might not be desirable.

This commit adds LoggingCacheErrorHandler constructor that accepts logger name and thus avoids leaking out any details about the underlying logging framework.
@vpavic vpavic force-pushed the logging-cache-error-handler-new-ctor branch from aceea82 to fa8e2e9 Compare October 19, 2022 11:19
@vpavic vpavic changed the base branch from main to 5.3.x October 19, 2022 11:20
@vpavic
Copy link
Contributor Author

vpavic commented Oct 19, 2022

That is done now. I also added a simple test just for the sake of having something in the codebase that uses the newly introduced constructor.

@jhoeller
Copy link
Contributor

Thanks, that was quick :-)

@jhoeller jhoeller self-assigned this Oct 19, 2022
@jhoeller jhoeller merged commit fb29137 into spring-projects:5.3.x Oct 19, 2022
@vpavic vpavic deleted the logging-cache-error-handler-new-ctor branch October 19, 2022 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants