Use scala-logging

This commit is contained in:
Michał Siatkowski
2022-08-09 21:59:49 +02:00
committed by Yevhen Zadyra
parent 07172866d9
commit de3c2ad9b1
21 changed files with 88 additions and 129 deletions

View File

@@ -1,4 +1,5 @@
dependencies {
api "ch.qos.logback:logback-classic:1.2.11"
api "org.typelevel:cats-core_$scala:2.8.0"
api "com.typesafe.scala-logging:scala-logging_$scala:3.9.5"
}

View File

@@ -1,45 +0,0 @@
package com.lbs.common
import org.slf4j
import org.slf4j.LoggerFactory
trait Logger {
private val log: slf4j.Logger = LoggerFactory.getLogger(this.getClass)
protected def debug(msg: => String): Unit = {
if (log.isDebugEnabled)
log.debug(msg)
}
protected def warn(msg: => String): Unit = {
if (log.isWarnEnabled)
log.warn(msg)
}
protected def warn(msg: => String, throwable: Throwable): Unit = {
if (log.isWarnEnabled)
log.warn(msg, throwable)
}
protected def error(msg: => String): Unit = {
if (log.isErrorEnabled)
log.error(msg)
}
protected def error(msg: => String, throwable: Throwable): Unit = {
if (log.isErrorEnabled)
log.error(msg, throwable)
}
protected def info(msg: => String): Unit = {
if (log.isInfoEnabled)
log.info(msg)
}
protected def trace(msg: => String): Unit = {
if (log.isTraceEnabled)
log.trace(msg)
}
}

View File

@@ -1,10 +1,12 @@
package com.lbs.common
import com.typesafe.scalalogging.LazyLogging
import java.util.concurrent.{Executors, ScheduledFuture}
import scala.concurrent.duration.FiniteDuration
class Scheduler(poolSize: Int) extends Logger {
class Scheduler(poolSize: Int) extends LazyLogging {
private val scheduledThreadPool = Executors.newScheduledThreadPool(poolSize)
def schedule(fn: => Unit, period: FiniteDuration): ScheduledFuture[_] = {
@@ -22,7 +24,7 @@ class Scheduler(poolSize: Int) extends Logger {
fn
} catch {
case ex: Exception =>
error(s"Unable to execute scheduler task", ex)
logger.error(s"Unable to execute scheduler task", ex)
}
}
}