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

Use SLF4J logging API in Typed #26537

Closed
patriknw opened this issue Mar 15, 2019 · 3 comments

Comments

@patriknw
Copy link
Member

commented Mar 15, 2019

Several things need investigation.

Background: akka/akka-meta#31

Two paths we have discussed:

  • have the typed logger (available from ActorContext.log) extend the SLF4J logging API but back it with the current logging infrastructure - this would likely not fulfill all wishes, but some of them and it would allow us to keep the current testing tools etc.
  • rely completely on SLF4J for the logging in typed actors - this means we would have to find ways to rewrite the testing tools (EventFilter and the log queue in BehaviorTestKit) to capture SLF4J log events

The untyped logging APIs will very likely not change.

For the testing tools this is a good resource: https://stackoverflow.com/questions/29076981/how-to-intercept-slf4j-logging-via-a-junit-test

If we decide to make this change it should be made in Akka 2.6, ApiMayChange option.

@patriknw patriknw added this to the 2.6 milestone Mar 15, 2019

@patriknw patriknw added this to Backlog in Akka Typed Mar 15, 2019

@patriknw patriknw changed the title Consider using SLF4J logging API in Typed Use SLF4J logging API in Typed Jul 2, 2019

@patriknw patriknw removed the discuss-design label Jul 2, 2019

@patriknw

This comment has been minimized.

Copy link
Member Author

commented Jul 2, 2019

We discussed this in the core team and we will give it a try.

  • ActorContext.log returns slf4j Logger
  • Document configuration, especially around async appender
  • Since logging from internals and untyped will still be with the eventStream it's important to configure the Akka Slf4jLogger when using Akka Typed. Perhaps we could do that automatically for Akka Typed?
  • Testing utilities, like the EventFilter in untyped testkit
    • preferably using some existing library
@patriknw

This comment has been minimized.

Copy link
Member Author

commented Jul 3, 2019

Related #24348

@patriknw patriknw moved this from Backlog 2.6 to In Progress in Akka Typed Jul 12, 2019

patriknw added a commit that referenced this issue Aug 28, 2019
Automatically enable eventStream Slf4jLogger for Typed, #26537
* amend the ActorSystem config on startup when config akka.use-slf4j=on
  and akka-slf4j in classpath
* akka.use-slf4j is defined in akka-actor-typed reference.conf
* also enable the Slf4jLoggingFilter automatically
* remove config in tests
patriknw added a commit that referenced this issue Aug 29, 2019
Automatically enable eventStream Slf4jLogger for Typed, #26537
* amend the ActorSystem config on startup when config akka.use-slf4j=on
  and akka-slf4j in classpath
* akka.use-slf4j is defined in akka-actor-typed reference.conf
* also enable the Slf4jLoggingFilter automatically
* remove config in tests
patriknw added a commit that referenced this issue Aug 29, 2019
Testing utility to silence logging until failure, #26537
* Logback appender that captures all log events and can flush them
  later to other appenders
* WithLogCapturing mixin for ScalaTest that flush the captured logging events
  when a test fails. Also clears the captured events after all tests.
* Configuration in logback-test.xml
patriknw added a commit that referenced this issue Aug 29, 2019
Testing utility to silence logging until failure, #26537
* Logback appender that captures all log events and can flush them
  later to other appenders
* WithLogCapturing mixin for ScalaTest that flush the captured logging events
  when a test fails. Also clears the captured events after all tests.
* Configuration in logback-test.xml
patriknw added a commit that referenced this issue Sep 1, 2019
Extension methods to Logger as workaround for overload and varargs pr…
…oblem, #26537

* "ambiguous reference to overloaded definition" for 2 arg method
* varargs not supported for primitive types
* providing extension methods info2 and infoN (and friends) via implicit class LoggerOps
  as more convenient workaround for these problems
patriknw added a commit that referenced this issue Sep 3, 2019
patriknw added a commit that referenced this issue Sep 4, 2019
Automatically enable eventStream Slf4jLogger for Typed, #26537 (#27583)
* amend the ActorSystem config on startup when config akka.use-slf4j=on
  and akka-slf4j in classpath
* akka.use-slf4j is defined in akka-actor-typed reference.conf
* also enable the Slf4jLoggingFilter automatically
* remove config in tests
patriknw added a commit that referenced this issue Sep 4, 2019
patriknw added a commit that referenced this issue Sep 4, 2019
Extension methods to Logger as workaround for overload and varargs pr…
…oblem, #26537 (#27605)

* "ambiguous reference to overloaded definition" for 2 arg method
* varargs not supported for primitive types
* providing extension methods info2 and infoN (and friends) via implicit class LoggerOps
  as more convenient workaround for these problems
patriknw added a commit that referenced this issue Sep 4, 2019
New API for Typed LoggingEventFilter, #26537
* builder style
* will make it easier to add more conditions
* all conditions are AND:ed together which makes it easier to define custom filters
* simplifies the implementation as a bonus
patriknw added a commit that referenced this issue Sep 5, 2019
New API for Typed LoggingEventFilter, #26537 (#27611)
* builder style
* will make it easier to add more conditions
* all conditions are AND:ed together which makes it easier to define custom filters
* simplifies the implementation as a bonus
* javadsl
* use new api in all tests
* leeway setting
* verify that occurrences = 0 works
* use javadsl in two tests
* change interceptLogger, and some other feedback
* minor wording of comments
patriknw added a commit that referenced this issue Sep 5, 2019
Complete logging with SLF4J in Typed, #26537
* TestAppender interaction with LoggingEventFilter
* LoggingEventFilter is now a close copy of classic EventFilter
* TestAppender plays the same role as classic TestEventList
* replace Sl4jLoggingEvent.java
  * include MDC in testkit.LoggingEvent to allow for custom filter
    testing MDC
* fix tests
* fix log events in BehaviorSetKit, using SubstituteLogger
* MDC in EventSourcedBehavior
  * using raw MDC to set the persistenceId and persistencePhase fields
  * avoid access to MDC ThreadLocal if log isn't used
* cleanup
* FIXMEs prefixed with issue number
patriknw added a commit that referenced this issue Sep 5, 2019
Automatically enable eventStream Slf4jLogger for Typed, #26537 (#27583)
* amend the ActorSystem config on startup when config akka.use-slf4j=on
  and akka-slf4j in classpath
* akka.use-slf4j is defined in akka-actor-typed reference.conf
* also enable the Slf4jLoggingFilter automatically
* remove config in tests
patriknw added a commit that referenced this issue Sep 5, 2019
Extension methods to Logger as workaround for overload and varargs pr…
…oblem, #26537 (#27605)

* "ambiguous reference to overloaded definition" for 2 arg method
* varargs not supported for primitive types
* providing extension methods info2 and infoN (and friends) via implicit class LoggerOps
  as more convenient workaround for these problems
patriknw added a commit that referenced this issue Sep 5, 2019
New API for Typed LoggingEventFilter, #26537 (#27611)
* builder style
* will make it easier to add more conditions
* all conditions are AND:ed together which makes it easier to define custom filters
* simplifies the implementation as a bonus
* javadsl
* use new api in all tests
* leeway setting
* verify that occurrences = 0 works
* use javadsl in two tests
* change interceptLogger, and some other feedback
* minor wording of comments
patriknw added a commit that referenced this issue Sep 5, 2019
Testing utility to silence logging until failure, #26537
* Logback appender that captures all log events and can flush them
  later to other appenders
* WithLogCapturing mixin for ScalaTest that flush the captured logging events
  when a test fails. Also clears the captured events after all tests.
* Configuration in logback-test.xml
patriknw added a commit that referenced this issue Sep 5, 2019
Complete logging with SLF4J in Typed, #26537
* TestAppender interaction with LoggingEventFilter
* LoggingEventFilter is now a close copy of classic EventFilter
* TestAppender plays the same role as classic TestEventList
* replace Sl4jLoggingEvent.java
  * include MDC in testkit.LoggingEvent to allow for custom filter
    testing MDC
* fix tests
* fix log events in BehaviorSetKit, using SubstituteLogger
* MDC in EventSourcedBehavior
  * using raw MDC to set the persistenceId and persistencePhase fields
  * avoid access to MDC ThreadLocal if log isn't used
* cleanup
* FIXMEs prefixed with issue number
patriknw added a commit that referenced this issue Sep 5, 2019
Automatically enable eventStream Slf4jLogger for Typed, #26537 (#27583)
* amend the ActorSystem config on startup when config akka.use-slf4j=on
  and akka-slf4j in classpath
* akka.use-slf4j is defined in akka-actor-typed reference.conf
* also enable the Slf4jLoggingFilter automatically
* remove config in tests
patriknw added a commit that referenced this issue Sep 5, 2019
Extension methods to Logger as workaround for overload and varargs pr…
…oblem, #26537 (#27605)

* "ambiguous reference to overloaded definition" for 2 arg method
* varargs not supported for primitive types
* providing extension methods info2 and infoN (and friends) via implicit class LoggerOps
  as more convenient workaround for these problems
patriknw added a commit that referenced this issue Sep 5, 2019
New API for Typed LoggingEventFilter, #26537 (#27611)
* builder style
* will make it easier to add more conditions
* all conditions are AND:ed together which makes it easier to define custom filters
* simplifies the implementation as a bonus
* javadsl
* use new api in all tests
* leeway setting
* verify that occurrences = 0 works
* use javadsl in two tests
* change interceptLogger, and some other feedback
* minor wording of comments
patriknw added a commit that referenced this issue Sep 5, 2019
Testing utility to silence logging until failure, #26537
* Logback appender that captures all log events and can flush them
  later to other appenders
* WithLogCapturing mixin for ScalaTest that flush the captured logging events
  when a test fails. Also clears the captured events after all tests.
* Configuration in logback-test.xml
patriknw added a commit that referenced this issue Sep 5, 2019
Testing utility to silence logging until failure, #26537 (#27588)
* Logback appender that captures all log events and can flush them
  later to other appenders
* LogCapturing mixin for ScalaTest that flush the captured logging events
  when a test fails. Also clears the captured events after all tests.
* Configuration in logback-test.xml
* log capturing for JUnit tests too, using TestRule
* Silence initial setup logging from Logback
* make LogCapturing public
* use LogCapturing in all tests
  * aside from multi-jvm so far
* a few doc tests needed debug level
patriknw added a commit that referenced this issue Sep 6, 2019
Complete logging with SLF4J in Typed, #26537
* TestAppender interaction with LoggingEventFilter
  * TestAppender plays the same role as classic TestEventList
* replace Sl4jLoggingEvent.java
  * include MDC in testkit.LoggingEvent to allow for custom filter
    testing MDC
* fix tests
* fix log events in BehaviorSetKit, using SubstituteLogger
* MDC in EventSourcedBehavior
  * using raw MDC to set the persistenceId and persistencePhase fields
  * avoid access to MDC ThreadLocal if log isn't used

* Automatically enable eventStream Slf4jLogger for Typed (PR #27583)
  * amend the ActorSystem config on startup when config akka.use-slf4j=on
    and akka-slf4j in classpath
  * akka.use-slf4j is defined in akka-actor-typed reference.conf
  * also enable the Slf4jLoggingFilter automatically
  * remove config in tests

* Include actor path as akkaSource in MDC (PR #27587)
  * move logger init to ActorContextImpl since not specific to untyped (ActorContextAdapter)
  * careful to not access MDC ThreadLocal if logging isn't used (per message)
  * MDC is cleared (if used) from aroundReceive in ActorAdapter after processing each message
  * also changed MDC for EventSourcedBehavior to rely on context.log and the outer MDC.clear()
  * just removing the MDC values is not enough because the empty Map remains in the ThreadLocal

* Optimization of MDC interceptor (PR #27610)

* Extension methods to Logger as workaround for overload and varargs problem (PR #27605)
  * "ambiguous reference to overloaded definition" for 2 arg method
  * varargs not supported for primitive types
  * providing extension methods info2 and infoN (and friends) via implicit class LoggerOps
    as more convenient workaround for these problems

* New API for Typed LoggingEventFilter (PR #27611)
  * builder style
  * will make it easier to add more conditions
  * all conditions are AND:ed together which makes it easier to define custom filters
  * simplifies the implementation as a bonus
  * javadsl
  * use new api in all tests
  * leeway setting
  * verify that occurrences = 0 works
  * use javadsl in two tests
  * change interceptLogger, and some other feedback

* Testing utility to silence logging until failure (PR #27588)
  * Logback appender that captures all log events and can flush them
    later to other appenders
  * LogCapturing mixin for ScalaTest that flush the captured logging events
    when a test fails. Also clears the captured events after all tests.
  * Configuration in logback-test.xml
  * log capturing for JUnit tests too, using TestRule
  * Silence initial setup logging from Logback
  * make LogCapturing public
  * use LogCapturing in all tests
    * aside from multi-jvm, and a few extending AkkaSpec, so far
  * a few doc tests needed debug level

* mention in migration guide
* rename setLoggerClass to setLoggerName
* check for logback dependency to give nicer error message
* fix filterKeys, deprecated in 2.13
patriknw added a commit that referenced this issue Sep 6, 2019

@patriknw patriknw modified the milestones: 2.6, 2.6.0-M7 Sep 6, 2019

@patriknw

This comment has been minimized.

Copy link
Member Author

commented Sep 6, 2019

Docs will come #27648

@patriknw patriknw closed this Sep 6, 2019

Akka Typed automation moved this from In Progress to Done Sep 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
1 participant
You can’t perform that action at this time.