This is an automated email from the ASF dual-hosted git repository.
chl501 pushed a commit to branch componentization
in repository https://gitbox.apache.org/repos/asf/hama.git
The following commit(s) were added to refs/heads/componentization by this push:
new c7ac873 Change Logging to trait for different implementations.
c7ac873 is described below
commit c7ac873b3e3bce613e1c46f0cb05f08ae5bb9f9f
Author: Chiahung Lin <[email protected]>
AuthorDate: Thu May 2 00:24:48 2019 +0200
Change Logging to trait for different implementations.
---
.../scala/org/apache/hama/logging/Logging.scala | 38 ++++++++++++++++++++--
.../org/apache/hama/membership/BSPMasterSpec.scala | 11 +++----
2 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/commons.v2/src/main/scala/org/apache/hama/logging/Logging.scala
b/commons.v2/src/main/scala/org/apache/hama/logging/Logging.scala
index 5b62a73..e322e4a 100644
--- a/commons.v2/src/main/scala/org/apache/hama/logging/Logging.scala
+++ b/commons.v2/src/main/scala/org/apache/hama/logging/Logging.scala
@@ -17,10 +17,44 @@
*/
package org.apache.hama.logging
+import org.slf4j.Logger
import org.slf4j.LoggerFactory
-trait Logging {
+trait Logging[T] {
- lazy val log = LoggerFactory.getLogger(getClass)
+ def info(message: String)
+ def debug(message: String)
+
+ def warn(message: String)
+
+ def trace(message: String)
+
+ def error(message: String)
+}
+
+object Logging {
+
+ def apply[T](implicit log: Logging[T]) = log
+
+ implicit def sl4fjLog: Logging[Logger] = new Logging[Logger] {
+
+ lazy val log = LoggerFactory.getLogger(getClass)
+
+ override def info(message: String) = if(log.isInfoEnabled)
+ log.info(message)
+
+ override def debug(message: String) = if(log.isDebugEnabled)
+ log.debug(message)
+
+ override def warn(message: String) = if(log.isWarnEnabled)
+ log.warn(message)
+
+ override def trace(message: String) = if(log.isTraceEnabled)
+ log.trace(message)
+
+ override def error(message: String) = if(log.isErrorEnabled)
+ log.error(message)
+
+ }
}
diff --git
a/membership/src/test/scala/org/apache/hama/membership/BSPMasterSpec.scala
b/membership/src/test/scala/org/apache/hama/membership/BSPMasterSpec.scala
index 8440dc5..93d6109 100644
--- a/membership/src/test/scala/org/apache/hama/membership/BSPMasterSpec.scala
+++ b/membership/src/test/scala/org/apache/hama/membership/BSPMasterSpec.scala
@@ -18,9 +18,8 @@
package org.apache.hama.membership
import org.scalatest._
-import org.apache.hama.logging.Logging
-class BSPMasterSpec extends FlatSpec with Matchers with Logging {
+class BSPMasterSpec extends FlatSpec with Matchers {
import BSPMaster._
import BSPMaster.State._
@@ -31,28 +30,28 @@ class BSPMasterSpec extends FlatSpec with Matchers with
Logging {
s <- stopped2Starting
} yield s
val startingState = starting.run(Right(Stopped)).value._1
- log.info(s"Actual BSPMaster state: $startingState")
+ println(s"Actual BSPMaster state: $startingState")
assert(Right(Starting).equals(startingState))
val running = for {
r <- starting2Running(ready)
} yield r
val runningState = running.run(startingState).value._1
- log.info(s"Actual BSPMaster state: $runningState")
+ println(s"Actual BSPMaster state: $runningState")
assert(Right(Running).equals(runningState))
val shuttingdown = for {
sd <- running2ShuttingDown(Set(CommunicatorShuttingDown))
} yield sd
val shuttingDownState = shuttingdown.run(runningState).value._1
- log.info(s"Actual BSPMaster state: $shuttingDownState")
+ println(s"Actual BSPMaster state: $shuttingDownState")
assert(Right(ShuttingDown).equals(shuttingDownState))
val _stopped_ = for {
s <- shuttingDown2Stopped(stopped)
} yield s
val stoppedState = _stopped_.run(shuttingDownState).value._1
- log.info(s"Actual BSPMaster state: $stoppedState")
+ println(s"Actual BSPMaster state: $stoppedState")
assert(Right(Stopped).equals(stoppedState))
}