2017-01-20 68 views
0

默認情況下,Jetty不會記錄任何級別高於WARN的級別,這對於嚴重錯誤(如OutOfMemory錯誤)不適用。 (大多數企業運營監控團隊在日誌中查找錯誤,而不是WARN。)更改致命錯誤的嵌入式Jetty日誌級別

如何安排日誌記錄,以便在ERROR級別報告這些致命錯誤?

回答

0

我發現,這是可以配置的logback使用ch.qos.logback.classic.turbo.TurboFilter

這裏調整日誌記錄在斯卡拉一種轉換例如,所有WARN到錯誤org.eclipse .jetty記錄儀:

import ch.qos.logback.classic.{Level, Logger} 
import ch.qos.logback.classic.turbo.TurboFilter 
import ch.qos.logback.core.spi.FilterReply 
import org.slf4j.{LoggerFactory, Marker} 

/** 
* Lift the log level of all WARN events to ERROR as Jetty will not 
* log anything above WARN level. 
*/ 
class JettyShoutyFilter extends TurboFilter { 
    val myLogger = LoggerFactory.getLogger(getClass) 

    override def decide(marker: Marker, logger: Logger, level: Level, format: String, params: Array[AnyRef], t: Throwable): FilterReply = { 
    if (isStarted && logger.getName.startsWith("org.eclipse.jetty") && level == Level.WARN && format != null) { 
     logger.error(marker, format, params) 
     FilterReply.DENY 
    } else FilterReply.NEUTRAL 
    } 
} 

添加記錄到你的配置這樣的:

<configuration> 
    <turboFilter class="JettyShoutyFilter"/> 
    ...