From 1b2f8481032d32f551219e3d76cc71a3cf8823a3 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Fri, 27 Sep 2019 12:33:43 +0200 Subject: [PATCH] Deprecate JavaLogger (java.utl.logging) --- .../scala/akka/event/jul/JavaLoggerSpec.scala | 2 + .../scala/akka/event/jul/JavaLogger.scala | 9 ++- akka-docs/src/main/paradox/logging.md | 58 +------------------ .../project/migration-guide-2.5.x-2.6.x.md | 5 ++ 4 files changed, 16 insertions(+), 58 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/event/jul/JavaLoggerSpec.scala b/akka-actor-tests/src/test/scala/akka/event/jul/JavaLoggerSpec.scala index 1310dbc710..9642f4cacb 100644 --- a/akka-actor-tests/src/test/scala/akka/event/jul/JavaLoggerSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/event/jul/JavaLoggerSpec.scala @@ -10,6 +10,7 @@ import akka.testkit.AkkaSpec import java.util.logging import scala.util.control.NoStackTrace +@deprecated("Use SLF4J instead.", "2.6.0") object JavaLoggerSpec { val config = ConfigFactory.parseString(""" @@ -31,6 +32,7 @@ object JavaLoggerSpec { class SimulatedExc extends RuntimeException("Simulated error") with NoStackTrace } +@deprecated("Use SLF4J instead.", "2.6.0") class JavaLoggerSpec extends AkkaSpec(JavaLoggerSpec.config) { val logger = logging.Logger.getLogger(classOf[JavaLoggerSpec.LogProducer].getName) diff --git a/akka-actor/src/main/scala/akka/event/jul/JavaLogger.scala b/akka-actor/src/main/scala/akka/event/jul/JavaLogger.scala index 4fec3e322f..894981aa96 100644 --- a/akka-actor/src/main/scala/akka/event/jul/JavaLogger.scala +++ b/akka-actor/src/main/scala/akka/event/jul/JavaLogger.scala @@ -19,6 +19,7 @@ import akka.util.unused /** * `java.util.logging` logger. */ +@deprecated("Use Slf4jLogger instead.", "2.6.0") class JavaLogger extends Actor with RequiresMessageQueue[LoggerMessageQueueSemantics] { import Logger.mapLevel @@ -27,7 +28,10 @@ class JavaLogger extends Actor with RequiresMessageQueue[LoggerMessageQueueSeman case event: Warning => log(mapLevel(event.level), null, event) case event: Info => log(mapLevel(event.level), null, event) case event: Debug => log(mapLevel(event.level), null, event) - case InitializeLogger(_) => sender() ! LoggerInitialized + case InitializeLogger(_) => + Logger(this.getClass.getName) + .warning(s"${getClass.getName} has been deprecated since Akka 2.6.0. Use SLF4J instead.") + sender() ! LoggerInitialized } def log(level: logging.Level, cause: Throwable, event: LogEvent): Unit = { @@ -45,6 +49,7 @@ class JavaLogger extends Actor with RequiresMessageQueue[LoggerMessageQueueSeman /** * Base trait for all classes that wants to be able use the JUL logging infrastructure. */ +@deprecated("Use SLF4J or direct java.util.logging instead.", "2.6.0") trait JavaLogging { @transient lazy val log: logging.Logger = Logger(this.getClass.getName) @@ -53,6 +58,7 @@ trait JavaLogging { /** * Logger is a factory for obtaining JUL Loggers */ +@deprecated("Use SLF4J or direct java.util.logging instead.", "2.6.0") object Logger { /** @@ -90,6 +96,7 @@ object Logger { * backend configuration to filter log events before publishing * the log events to the `eventStream`. */ +@deprecated("Use Slf4jLoggingFilter instead.", "2.6.0") class JavaLoggingFilter(@unused settings: ActorSystem.Settings, eventStream: EventStream) extends LoggingFilter { import Logger.mapLevel diff --git a/akka-docs/src/main/paradox/logging.md b/akka-docs/src/main/paradox/logging.md index fd4896e1dc..48548c6a65 100644 --- a/akka-docs/src/main/paradox/logging.md +++ b/akka-docs/src/main/paradox/logging.md @@ -7,7 +7,7 @@ For the new API see @ref[Logging](typed/logging.md). ## Dependency -To use Logging, you must at least use the Akka actors dependency in your project, and will most likely want to configure logging via the SLF4J module (@ref:[see below](#slf4j)), or use `java.util.logging` (@ref:[see below](#java-util-logging)). +To use Logging, you must at least use the Akka actors dependency in your project, and will most likely want to configure logging via the SLF4J module (@ref:[see below](#slf4j)). @@dependency[sbt,Maven,Gradle] { group="com.typesafe.akka" @@ -583,59 +583,3 @@ Since the akka-actor library avoids depending on any specific logging library, t which provides the `Slf4jLogMarker` type which can be passed in as first argument instead of the logging framework agnostic LogMarker type from `akka-actor`. The most notable difference between the two is that slf4j's Markers can have child markers, so one can rely more information using them rather than just a single string. - - - -## java.util.logging - -Akka includes a logger for [java.util.logging](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html#package.description). - -You need to enable the `akka.event.jul.JavaLogger` in the `loggers` element in -the @ref:[configuration](general/configuration.md). Here you can also define the log level of the event bus. -More fine grained log levels can be defined in the configuration of the logging backend. -You should also define `akka.event.jul.JavaLoggingFilter` in -the `logging-filter` configuration property. It will filter the log events using the backend -configuration before they are published to the event bus. - -@@@ warning - -If you set the `loglevel` to a higher level than `DEBUG`, any `DEBUG` events will be filtered -out already at the source and will never reach the logging backend, regardless of how the backend -is configured. - -@@@ - -```ruby -akka { - loglevel = DEBUG - loggers = ["akka.event.jul.JavaLogger"] - logging-filter = "akka.event.jul.JavaLoggingFilter" -} -``` - -One gotcha is that the timestamp is attributed in the event handler, not when actually doing the logging. - -The `java.util.logging.Logger` selected for each log event is chosen based on the -@scala[`Class[_]`]@java[`Class`] of the log source specified when creating the -`LoggingAdapter`, unless that was given directly as a string in which -case that string is used (i.e. @scala[`LoggerFactory.getLogger(c: Class[_])`] @java[`LoggerFactory.getLogger(Class c)`] is used in -the first case and @scala[`LoggerFactory.getLogger(s: String)`] @java[`LoggerFactory.getLogger(String s)`] in the second). - -@@@ note - -Beware that the actor system’s name is appended to a `String` log -source if the LoggingAdapter was created giving an `ActorSystem` to -the factory. If this is not intended, give a `LoggingBus` instead as -shown below: - -@@@ - -Scala -: ```scala -val log = Logging(system.eventStream, "my.nice.string") -``` - -Java -: ```java - final LoggingAdapter log = Logging.getLogger(system.eventStream(), "my.string"); - ``` diff --git a/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md b/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md index b44ab88b4f..377ab52d9d 100644 --- a/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md +++ b/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md @@ -154,6 +154,11 @@ deprecated and replaced with corresponding methods that takes a factory function See documentation of @ref:[streaming IO with TLS](../stream/stream-io.md#tls). +### JavaLogger + +`akka.event.jul.JavaLogger` for integration with `java.util.logging` has been deprecated. Use SLF4J instead, +which also has support for `java.util.logging`. + ### akka.Main `akka.Main` is deprecated in favour of starting the `ActorSystem` from a custom main class instead. `akka.Main` was not