All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scribe.jul.JULHandler.scala Maven / Gradle / Ivy

There is a newer version: 3.15.3
Show newest version
package scribe.jul

import scribe._

import java.util.logging.{Level => JLevel}

object JULHandler extends java.util.logging.Handler {
  override def publish(record: java.util.logging.LogRecord): Unit = {
    val logger = scribe.Logger(record.getLoggerName)
    val level = l2l(record.getLevel)
    val logRecord = LogRecord(
      level = level,
      levelValue = level.value,
      messages = List(record.getMessage),
      fileName = "",
      className = Option(record.getSourceClassName).getOrElse(record.getLoggerName),
      methodName = Option(record.getSourceMethodName),
      line = None,
      column = None
    )
    logger.log(logRecord)
  }

  private def l2l(level: JLevel): Level = level match {
    case JLevel.FINEST => Level.Trace
    case JLevel.FINER => Level.Trace
    case JLevel.FINE => Level.Trace
    case JLevel.CONFIG => Level.Debug
    case JLevel.INFO => Level.Info
    case JLevel.WARNING => Level.Warn
    case JLevel.SEVERE => Level.Error
    case JLevel.OFF => Level.Trace
    case JLevel.ALL => Level.Fatal
  }

  override def flush(): Unit = {}

  override def close(): Unit = {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy