从SMTPAppender配置日志级别

时间:2019-03-11 09:42:20

标签: logging log4j2

如何仅在smtp附加程序中包括警告和更高级别的事件?

  

SMTPAppender仅将最后的BufferSize日志记录事件保留在其循环缓冲区中。这将内存需求保持在合理的水平,同时仍提供有用的应用程序上下文。缓冲区中的所有事件都包含在电子邮件中。缓冲区将包含触发电子邮件的事件之前级别为 TRACE WARN 的最新事件。

     

默认行为是在记录 ERROR 或更高严重性事件时触发发送电子邮件,并将其格式化为HTML。可以通过在Appender上设置一个或多个过滤器来控制发送电子邮件的时间。   Log4j2 SMTPAppender

根据此comment电子邮件发送事件绑定到阈值过滤器。配置阈值过滤器会更改触发发送电子邮件的事件级别,但不会影响将保存在缓冲区中的事件。

更改记录器级别本身是不可行的,因为事件也应由其他附加程序处理。

import java.io.IOException
import scala.util.Try
import org.apache.hadoop.hive.cli.CliSessionState
import org.apache.hadoop.hive.conf.HiveConf
import org.apache.hadoop.hive.ql.Driver
import org.apache.hadoop.hive.ql.session.SessionState

class getData {
  val hiveConf = new HiveConf(classOf[getData])

  private def getDriver: Driver = {
    val driver = new Driver(hiveConf)
    SessionState.start(new CliSessionState(hiveConf))
    driver
  }

  def executeHQL(hql: String): Int = {
    val responseOpt = Try(getDriver.run(hql)).toEither
    val response = responseOpt match {
      case Right(response) => response
      case Left(exception) => throw new Exception(s"${ exception.getMessage }")
    }
    val responseCode = response.getResponseCode
    if (responseCode != 0) {
      val err: String = response.getErrorMessage
      throw new IOException("Failed to execute hql [" + hql + "], error message is: " + err)
    }
    responseCode
  }
}

0 个答案:

没有答案
相关问题