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

Add Throwable "cause" variants to warning log API #30389

Closed
wants to merge 6 commits into from

Conversation

emanb29
Copy link
Contributor

@emanb29 emanb29 commented Jul 11, 2021

Adds variants to log.warning to bring it closer to log.error, in particular, adding a cause: Throwable.

A (not-so-hypothetical) use-case for this is an application for which there are a set of recoverable errors, which do not interfere with application functionality, but do indicate an error on the end-user's part. In such a case, it can be helpful to log a warning, and convenient to pass along the Throwable that caused said warning, in a way that is consistent with log.error

@akka-ci
Copy link

akka-ci commented Jul 11, 2021

Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK ΤO ΤESΤ' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged.

For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask!

@octonato
Copy link
Member

@emanb29, the build is failing because of bin-incompatibility with previous API.

You will need to add a mima exclusion for

ProblemFilters.exclude[ReversedMissingMethodProblem("akka.event.LoggingAdapter.notifyWarning")

You do that by adding a file similar to
https://github.com/akka/akka/blob/master/akka-actor/src/main/mima-filters/2.6.14.backwards.excludes/30267-supervision-loglevel.excludes

Note that you will need add the file under 2.6.15.backwards.excludes instead.

Now, concerning the addition, I checked how logback and log4j do the same and indeed they do have overloaded variants accepting a Throwable for all log levels.

I'm not sure what was the rationale behind the decision to not do the same in akka logging. Maybe something worth reconsider. Maybe others (@johanandren, @jrudolph, @patriknw) have more insight on why it wasn't added.

emanb29 and others added 2 commits July 12, 2021 10:14
Co-authored-by: Renato Cavalcanti <renato@cavalcanti.be>
@emanb29
Copy link
Contributor Author

emanb29 commented Jul 12, 2021

Thanks @octonato! I made a copy/paste error but I found the travis command and am re-checking locally before updating the branch again.

@jrudolph
Copy link
Member

You will need to add a mima exclusion for

ProblemFilters.exclude[ReversedMissingMethodProblem("akka.event.LoggingAdapter.notifyWarning")

This might be an actual incompatibility, as this is a public class that might be implemented by third parties. If we want to include this, we might want to include a default implementation that calls the existing notifyWarning method (and throws away the Throwable).

I'm not sure what was the rationale behind the decision to not do the same in akka logging. Maybe something worth reconsider. Maybe others (@johanandren, @jrudolph, @patriknw) have more insight on why it wasn't added.

I don't know but maybe it was just missed in the beginning and compatibility requirements prevented it afterwards?

Personally, I'm not against adding it when the compat issues can be resolved.

@octonato
Copy link
Member

This might be an actual incompatibility, as this is a public class that might be implemented by third parties. If we want to include this, we might want to include a default implementation that calls the existing notifyWarning method (and throws away the Throwable).

That's true, but I'm wondering which scenario you have in mind where a method addition could cause a problem. If I'm using such 3rd party library and I update my Akka version, the Akka version used by the 3rd party library will be evicted, no?

@johanandren
Copy link
Member

The third party library could contain a subclass, that is not recompiled by upgrading Akka so does not have the new method. The third party library-case is in general the most problematic scenario with binary compatibility, compared to a users own leaf-project where sources are easier to recompile to fix a binary compatibility.

Not sure how likely that is in this case but we should step carefully. A default impl might work, but we should verify that.

@octonato
Copy link
Member

A default impl might work, but we should verify that.

I created a small project containing three sub-projects: logger, logger-wrapper and app.

Adding a default impl for the new method as suggested by @jrudolph does the trick (as expected).

Please, check readme file to understand how I tested it. I think this test covers the case here. Let me know if I missed something.

@johanandren
Copy link
Member

Double checked the idea of default implementation with both 2.13 and 2.12 and that works fine (because Scalac turns the trait into an interface with default methods)

Co-authored-by: Johan Andrén <johan@markatta.com>
@@ -1199,6 +1199,7 @@ trait LoggingAdapter {
protected def notifyError(message: String): Unit
protected def notifyError(cause: Throwable, message: String): Unit
protected def notifyWarning(message: String): Unit
protected def notifyWarning(cause: Throwable, message: String): Unit = notifyWarning(message)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
protected def notifyWarning(cause: Throwable, message: String): Unit = notifyWarning(message)
protected def notifyWarning(@unused cause: Throwable, message: String): Unit = notifyWarning(message)

@@ -1981,6 +2025,8 @@ class BusLogging(val bus: LoggingBus, val logSource: String, val logClass: Class
bus.publish(Error(cause, logSource, logClass, message, mdc))
protected def notifyWarning(message: String): Unit =
bus.publish(Warning(logSource, logClass, message, mdc))
protected def notifyWarning(cause: Throwable, message: String): Unit =
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
protected def notifyWarning(cause: Throwable, message: String): Unit =
override protected def notifyWarning(cause: Throwable, message: String): Unit =

@@ -0,0 +1,2 @@
# additional overload added
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.event.LoggingAdapter.notifyWarning")
Copy link
Member

Choose a reason for hiding this comment

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

I tried it out and it looks like we can delete this exclude now and MiMa is still happy

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

looking good

@@ -1981,6 +2025,8 @@ class BusLogging(val bus: LoggingBus, val logSource: String, val logClass: Class
bus.publish(Error(cause, logSource, logClass, message, mdc))
protected def notifyWarning(message: String): Unit =
bus.publish(Warning(logSource, logClass, message, mdc))
protected def notifyWarning(cause: Throwable, message: String): Unit =
bus.publish(Warning(cause, logSource, logClass, message, mdc))
Copy link
Member

Choose a reason for hiding this comment

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

Funny that we had prepared for it with that Warning4 class, but not exposing it in the LoggingAdapter. Must have been an oversight.

@patriknw
Copy link
Member

patriknw commented Sep 1, 2022

Completed in #31525

@patriknw patriknw closed this Sep 1, 2022
@patriknw
Copy link
Member

patriknw commented Sep 2, 2022

@emanb29 Could you complete this in this original PR instead? Github is stupid in the way that it will change the author to me if we merge it from my PR. What I did was to remove the mima exclude files and added some @nowarn and @override that the compiler complained about. See #31525

@patriknw
Copy link
Member

patriknw commented Sep 6, 2022

Merged to main as 044bb2d

@patriknw patriknw closed this Sep 6, 2022
@patriknw patriknw added this to the 2.6.20 milestone Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants