Logging.scala 674 Bytes
Newer Older
杜发飞 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package com.hikcreate.data.common

import org.slf4j.{Logger, LoggerFactory}

trait Logging {

  private def log: Logger =  LoggerFactory.getLogger(this.getClass.getName.stripSuffix("$"))

  protected def debug(msg: => String): Unit =  if (log.isDebugEnabled) log.debug(msg)

  protected def info(msg: => String): Unit = if (log.isInfoEnabled) log.info(msg)

  protected def warn(msg: => String): Unit = if (log.isWarnEnabled) log.warn(msg)

  protected def error(msg: => String):Unit = if (log.isErrorEnabled) log.error(msg)

  protected def error(msg: => String,exception:Exception):Unit = if (log.isErrorEnabled) {
    log.error(msg)
    exception.printStackTrace()
  }
}