From 8194ddd13c4992ed732773c971aafa0b2b9d5df8 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Thu, 15 Nov 2012 02:31:40 +0100 Subject: [PATCH] #2703 - unprivatizing NoLogging and adding a Java API for obtaining the reference --- .../test/java/akka/japi/JavaAPITestBase.java | 8 +++++ .../src/main/scala/akka/event/Logging.scala | 30 ++++++++++++------- .../code/docs/event/LoggingDocTestBase.java | 1 - 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/akka-actor-tests/src/test/java/akka/japi/JavaAPITestBase.java b/akka-actor-tests/src/test/java/akka/japi/JavaAPITestBase.java index c0361530da..b3a092b1f9 100644 --- a/akka-actor-tests/src/test/java/akka/japi/JavaAPITestBase.java +++ b/akka-actor-tests/src/test/java/akka/japi/JavaAPITestBase.java @@ -1,5 +1,7 @@ package akka.japi; +import akka.event.LoggingAdapter; +import akka.event.NoLogging; import org.junit.Test; import static org.junit.Assert.*; @@ -46,4 +48,10 @@ public class JavaAPITestBase { public void shouldBeSingleton() { assertSame(Option.none(), Option.none()); } + + @Test + public void mustBeAbleToGetNoLogging() { + LoggingAdapter a = NoLogging.getInstance(); + assertNotNull(a); + } } diff --git a/akka-actor/src/main/scala/akka/event/Logging.scala b/akka-actor/src/main/scala/akka/event/Logging.scala index dbd561514d..14ba99bcaa 100644 --- a/akka-actor/src/main/scala/akka/event/Logging.scala +++ b/akka-actor/src/main/scala/akka/event/Logging.scala @@ -878,15 +878,25 @@ class BusLogging(val bus: LoggingBus, val logSource: String, val logClass: Class protected def notifyDebug(message: String): Unit = bus.publish(Debug(logSource, logClass, message)) } -private[akka] object NoLogging extends LoggingAdapter { - def isErrorEnabled = false - def isWarningEnabled = false - def isInfoEnabled = false - def isDebugEnabled = false +/** + * NoLogging is a LoggingAdapter that does absolutely nothing – no logging at all. + */ +object NoLogging extends LoggingAdapter { - protected def notifyError(message: String): Unit = () - protected def notifyError(cause: Throwable, message: String): Unit = () - protected def notifyWarning(message: String): Unit = () - protected def notifyInfo(message: String): Unit = () - protected def notifyDebug(message: String): Unit = () + /** + * Java API to return the reference to NoLogging + * @return The NoLogging instance + */ + def getInstance = this + + final override def isErrorEnabled = false + final override def isWarningEnabled = false + final override def isInfoEnabled = false + final override def isDebugEnabled = false + + final protected override def notifyError(message: String): Unit = () + final protected override def notifyError(cause: Throwable, message: String): Unit = () + final protected override def notifyWarning(message: String): Unit = () + final protected override def notifyInfo(message: String): Unit = () + final protected override def notifyDebug(message: String): Unit = () } diff --git a/akka-docs/rst/java/code/docs/event/LoggingDocTestBase.java b/akka-docs/rst/java/code/docs/event/LoggingDocTestBase.java index 54847c4f66..3e3fa46844 100644 --- a/akka-docs/rst/java/code/docs/event/LoggingDocTestBase.java +++ b/akka-docs/rst/java/code/docs/event/LoggingDocTestBase.java @@ -119,5 +119,4 @@ public class LoggingDocTestBase { } } //#deadletter-actor - }