2017-09-13 65 views
4

這是我log4j2 JSON配置主要錯誤無法找到的appender「測試」記錄器配置「測試」

{ 
"Configuration": { 
    "Appenders": { 
     "Console": { 
     "PatternLayout": { 
     "pattern": "%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" 
    }, 
    "name": "Console", 
    "target": "SYSTEM_OUT" 
    }, 
    "RollingFile": { 
    "name": "general", 
    "fileName": "C:/logs/simulator-log.log", 
    "filePattern": "C:/logs/simulator-log-%d{yyyy-MM-dd HH-mm-ss}.log", 
    "PatternLayout": { 
     "pattern": "%msg%n" 

    }, 
    "Policies": { 

     "OnStartupTriggeringPolicy": { 
     } 
    } 
    }, 
    "File": { 
    "PatternLayout": { 
     "pattern":"%msg%n" 
    }, 
    "name": "test", 
    "fileName": "c:/logs/requests_received.log" 
    }, 
    "File": { 
    "PatternLayout": { 
     "pattern":"%msg%n" 
    }, 
    "name": "test1", 
    "fileName": "c:/logs/response_sent.log" 
    } 
    }, 
    "Loggers": { 
    "Root": { 
     "AppenderRef": [ 
     { 
      "ref": "Console" 
     } 
     ], 
     "level": "trace" 
    }, 
    "logger": [ 
     { 
     "name": "test", 
     "level": "trace", 
     "additivity":"false", 
     "AppenderRef": { 
      "ref": "test" 
     } 
     }, 
     { 
     "name": "test1", 
     "level": "trace", 
     "additivity":"false", 
     "AppenderRef": { 
      "ref": "test1" 
     } 
     }, 
     { 
     "name": "general", 
     "level": "trace", 
     "additivity":"false", 
     "AppenderRef": { 
      "ref": "general" 
     } 
     } 
    ] 
    } 
} 

}

當我使用一個文件追加程序正常工作。當我使用兩個文件appender在title.cant中提到錯誤時,我們添加了多個文件appender。我不想使用滾動文件appender。

請忽略此內容「看起來你的文章主要是代碼,請添加一些更多的細節,你想要什麼更多的細節?我想我已經傳達了一切,還有什麼你想讓我補充的。問題。」創建記錄變量

private static final Logger requestsReceived = LogManager.getLogger("test"); 
private static final Logger responseSent = LogManager.getLogger("test1"); 
private static final Logger logger = LogManager.getLogger("general"); 

回答

2

嘗試使用來定義您的appender type屬性像下面

Java代碼 -

{ 
    "type": "File", 
    "PatternLayout": { 
     "pattern": "%msg%n" 
    }, 
    "name": "test", 
    "fileName": "c:/logs/requests_received.log" 
}, 
{ 
    "type": "File", 
    "PatternLayout": { 
     "pattern": "%msg%n" 
    }, 
    "name": "test1", 
    "fileName": "c:/logs/response_sent.log" 
} 

對於這一點,你必須使用type屬性修改所有的appender配置。您的完整配置文件將如下更改 -

{ 
    "Configuration": { 
     "Appenders": { 
      "appender": [ 
       { 
        "type": "Console", 
        "PatternLayout": { 
         "pattern": "%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" 
        }, 
        "name": "Console", 
        "target": "SYSTEM_OUT" 
       }, 
       { 
        "type": "RollingFile", 
        "name": "general", 
        "fileName": "C:/logs/simulator-log.log", 
        "filePattern": "C:/logs/simulator-log-%d{yyyy-MM-dd HH-mm-ss}.log", 
        "PatternLayout": { 
         "pattern": "%msg%n" 
        }, 
        "Policies": { 
         "OnStartupTriggeringPolicy": { 

         } 
        } 
       }, 
       { 
        "type": "File", 
        "PatternLayout": { 
         "pattern": "%msg%n" 
        }, 
        "name": "test", 
        "fileName": "c:/logs/requests_received.log" 
       }, 
       { 
        "type": "File", 
        "PatternLayout": { 
         "pattern": "%msg%n" 
        }, 
        "name": "test1", 
        "fileName": "c:/logs/response_sent.log" 
       } 
      ] 
     }, 
     "Loggers": { 
      "Root": { 
       "AppenderRef": [ 
        { 
         "ref": "Console" 
        } 
       ], 
       "level": "trace" 
      }, 
      "logger": [ 
       { 
        "name": "test", 
        "level": "trace", 
        "additivity": "false", 
        "AppenderRef": { 
         "ref": "test" 
        } 
       }, 
       { 
        "name": "test1", 
        "level": "trace", 
        "additivity": "false", 
        "AppenderRef": { 
         "ref": "test1" 
        } 
       }, 
       { 
        "name": "general", 
        "level": "trace", 
        "additivity": "false", 
        "AppenderRef": { 
         "ref": "general" 
        } 
       } 
      ] 
     } 
    } 
} 
+0

它的工作原理。非常感謝您提供完整的json配置。 – hmmm