1. 程式人生 > >Java log4j.additivity取消日誌繼承為何無效

Java log4j.additivity取消日誌繼承為何無效

com active 分析 log4 配置 num 繼承關系 currency 留言

log4j1日誌繼承說明: 略.

簡短說明問題原因: "log4j.additivity"後邊跟的包路徑必須和另一項配置"log4j.logger"後邊跟的包路徑能對上, log4j不會分析你的項目的包結構.

  例如:考慮取消com.game.gmActivation.logger包下的幾個logger的繼承關系, 只輸出到指定路徑的日誌裏, 錯誤的配置是只寫一條父級包路徑配置:

    # 以下包路徑的日誌取消繼承

    log4j.additivity.com.game.gmActivation.logger=false

    ##行為日誌定向配置
    log4j.logger.com.game.gmActivation.logger.gameCurrency=INFO,gameCurrencyLog


    log4j.logger.com.game.gmActivation.logger.onlineRoleNum=INFO,onlineRoleNumLog
    log4j.logger.com.game.gmActivation.logger.itemBuy=INFO,itemBuyLog
    log4j.logger.com.game.gmActivation.logger.zuanshiUse=INFO,zuanshiUseLog
    log4j.logger.com.game.gmActivation.logger.gameSysActive=INFO,gameSysActiveLog

  

正確的配置為列舉全部配置, 一一對應. 

    # 以下包路徑的日誌取消繼承
    log4j.additivity.com.game.gmActivation.logger.gameCurrency=false
    log4j.additivity.com.game.gmActivation.logger.onlineRoleNum=false
    log4j.additivity.com.game.gmActivation.logger.itemBuy=false
    log4j.additivity.com.game.gmActivation.logger.zuanshiUse=false


    log4j.additivity.com.game.gmActivation.logger.gameSysActive=false
    ##行為日誌定向配置
    log4j.logger.com.game.gmActivation.logger.gameCurrency=INFO,gameCurrencyLog
    log4j.logger.com.game.gmActivation.logger.onlineRoleNum=INFO,onlineRoleNumLog
    log4j.logger.com.game.gmActivation.logger.itemBuy=INFO,itemBuyLog
    log4j.logger.com.game.gmActivation.logger.zuanshiUse=INFO,zuanshiUseLog
    log4j.logger.com.game.gmActivation.logger.gameSysActive=INFO,gameSysActiveLog

歡迎留言指正.

Java log4j.additivity取消日誌繼承為何無效