-1
我想通過名稱獲取記錄器,因爲我有多個記錄器,但仍打印記錄該消息的類的類名。感謝幫助。按名稱獲取記錄器,打印類名稱
實施例:
<!--Loggers...-->
<logger name="LoggerA"><appender-ref="AppenderA"></appender></logger>
<logger name="LoggerB"><appender-ref="AppenderB"></appender></logger>
<logger name="LoggerC"><appender-ref="AppenderC"></appender></logger>
假設每個這些記錄器將寫入到一個不同*.log
文件。
<<From ClassXYZ>>
private static final Logger LOGA = LoggerFactory.getLogger("LoggerA");
private static final Logger LOGB = LoggerFactory.getLogger("LoggerB");
private static final Logger LOGC = LoggerFactory.getLogger("LoggerC");
中的每個文件,會出現下面的語句:
2017-04-06 18:23:12,538 [main] [] INFO LoggerA - <<Some Log Message>>
2017-04-06 18:23:12,538 [main] [] INFO LoggerB - <<Some Log Message>>
2017-04-06 18:23:12,538 [main] [] INFO LoggerC - <<Some Log Message>>
但是我希望/希望它被記錄爲:
2017-04-06 18:23:12,538 [main] [] INFO ClassXYZ - <<Some Log Message>>
2017-04-06 18:23:12,538 [main] [] INFO ClassXYZ - <<Some Log Message>>
2017-04-06 18:23:12,538 [main] [] INFO ClassXYZ - <<Some Log Message>>
我的模式是:
%d [%thread] [%X{CONTEXT}] %-5level %logger{70} - %msg%n
被此爲你工作私有靜態最後記錄器LOGA = LoggerFactory.getLogger(ClassXYZ.class); ? – utkusonmez