Merge pull request #27811 from akka/wip-more-deprecation-2-patriknw

Deprecate JavaLogger (java.utl.logging)
This commit is contained in:
Patrik Nordwall 2019-10-10 16:30:22 +02:00 committed by GitHub
commit e40a2591d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 58 deletions

View file

@ -10,6 +10,7 @@ import akka.testkit.AkkaSpec
import java.util.logging import java.util.logging
import scala.util.control.NoStackTrace import scala.util.control.NoStackTrace
@deprecated("Use SLF4J instead.", "2.6.0")
object JavaLoggerSpec { object JavaLoggerSpec {
val config = ConfigFactory.parseString(""" val config = ConfigFactory.parseString("""
@ -31,6 +32,7 @@ object JavaLoggerSpec {
class SimulatedExc extends RuntimeException("Simulated error") with NoStackTrace class SimulatedExc extends RuntimeException("Simulated error") with NoStackTrace
} }
@deprecated("Use SLF4J instead.", "2.6.0")
class JavaLoggerSpec extends AkkaSpec(JavaLoggerSpec.config) { class JavaLoggerSpec extends AkkaSpec(JavaLoggerSpec.config) {
val logger = logging.Logger.getLogger(classOf[JavaLoggerSpec.LogProducer].getName) val logger = logging.Logger.getLogger(classOf[JavaLoggerSpec.LogProducer].getName)

View file

@ -19,6 +19,7 @@ import akka.util.unused
/** /**
* `java.util.logging` logger. * `java.util.logging` logger.
*/ */
@deprecated("Use Slf4jLogger instead.", "2.6.0")
class JavaLogger extends Actor with RequiresMessageQueue[LoggerMessageQueueSemantics] { class JavaLogger extends Actor with RequiresMessageQueue[LoggerMessageQueueSemantics] {
import Logger.mapLevel 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: Warning => log(mapLevel(event.level), null, event)
case event: Info => 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 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 = { 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. * 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 { trait JavaLogging {
@transient @transient
lazy val log: logging.Logger = Logger(this.getClass.getName) lazy val log: logging.Logger = Logger(this.getClass.getName)
@ -53,6 +58,7 @@ trait JavaLogging {
/** /**
* Logger is a factory for obtaining JUL Loggers * Logger is a factory for obtaining JUL Loggers
*/ */
@deprecated("Use SLF4J or direct java.util.logging instead.", "2.6.0")
object Logger { object Logger {
/** /**
@ -90,6 +96,7 @@ object Logger {
* backend configuration to filter log events before publishing * backend configuration to filter log events before publishing
* the log events to the `eventStream`. * the log events to the `eventStream`.
*/ */
@deprecated("Use Slf4jLoggingFilter instead.", "2.6.0")
class JavaLoggingFilter(@unused settings: ActorSystem.Settings, eventStream: EventStream) extends LoggingFilter { class JavaLoggingFilter(@unused settings: ActorSystem.Settings, eventStream: EventStream) extends LoggingFilter {
import Logger.mapLevel import Logger.mapLevel

View file

@ -7,7 +7,7 @@ For the new API see @ref[Logging](typed/logging.md).
## Dependency ## 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] { @@dependency[sbt,Maven,Gradle] {
group="com.typesafe.akka" 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 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 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. rely more information using them rather than just a single string.
<a id="jul"></a>
## 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 systems 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");
```

View file

@ -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). 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
`akka.Main` is deprecated in favour of starting the `ActorSystem` from a custom main class instead. `akka.Main` was not `akka.Main` is deprecated in favour of starting the `ActorSystem` from a custom main class instead. `akka.Main` was not