LogType.scala 2.3 KB
Newer Older
1
/*
梦境迷离's avatar
梦境迷离 已提交
2
 * Copyright (c) 2021 org.bitlap
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

梦境迷离's avatar
梦境迷离 已提交
22
package org.bitlap.tools.logs
梦境迷离's avatar
梦境迷离 已提交
23

梦境迷离's avatar
梦境迷离 已提交
24 25
import org.bitlap.tools.PACKAGE
import org.bitlap.tools.logs.extension.{ ScalaLoggingLazyImpl, ScalaLoggingStrictImpl }
梦境迷离's avatar
梦境迷离 已提交
26 27 28 29

object LogType extends Enumeration {

  type LogType = Value
梦境迷离's avatar
梦境迷离 已提交
30
  val JLog, Log4j2, Slf4j, ScalaLoggingLazy, ScalaLoggingStrict = Value
梦境迷离's avatar
梦境迷离 已提交
31

梦境迷离's avatar
梦境迷离 已提交
32 33 34 35 36 37
  private lazy val types: Map[LogType, BaseLog] = Map(
    JLogImpl.`type` -> JLogImpl,
    Log4J2Impl.`type` -> Log4J2Impl,
    Slf4jImpl.`type` -> Slf4jImpl,
    ScalaLoggingStrictImpl.`type` -> ScalaLoggingStrictImpl,
    ScalaLoggingLazyImpl.`type` -> ScalaLoggingLazyImpl
梦境迷离's avatar
梦境迷离 已提交
38 39
  )

梦境迷离's avatar
梦境迷离 已提交
40
  def getLogImpl(logType: LogType): BaseLog = {
41 42 43
    types.getOrElse(logType, default = throw new Exception(s"Not support log type: $logType"))
  }

梦境迷离's avatar
梦境迷离 已提交
44
  def getLogType(shortType: String): LogType = {
梦境迷离's avatar
梦境迷离 已提交
45 46
    val tpe1 = s"$PACKAGE.logs.$shortType" //LogType.JLog
    val tpe2 = s"$PACKAGE.logs.LogType.$shortType" // JLog
47
    val v = LogType.values.find(p => {
梦境迷离's avatar
梦境迷离 已提交
48 49
      s"$PACKAGE.logs.LogType.${p.toString}" == tpe1 ||
        s"$PACKAGE.logs.LogType.${p.toString}" == tpe2 || s"$PACKAGE.logs.LogType.${p.toString}" == shortType
50 51
    }).getOrElse(throw new Exception(s"Not support log type: $shortType")).toString
    LogType.withName(v)
梦境迷离's avatar
梦境迷离 已提交
52 53 54
  }
}