2013-05-21 48 views
0

是否可以在logback中使用MessageFormat?LogBack使用MessageFormat

我看到它使用SLF4J的MessageFormat 之三,因爲它的速度更快的在這裏說: Out of curiosity -- why don't logging APIs implement printf()-like logging methods?

SLF4J使用自己的郵件格式實現它不同於Java平臺的 。這是有道理的,因爲SLF4J的實現執行速度大約快10倍,但代價是 ,這是非標準的並且不夠靈活。

From sf4j Documentation

的IDEIA是用那樣的MessageFormat的完整的堆棧功能:

Object[] arguments = { 
    new Integer(7), 
    new Date(System.currentTimeMillis()), 
    "a disturbance in the Force" 
}; 

String result = MessageFormat.format(
    "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", 
    arguments); 

output: At 12:30 PM on Jul 3, 2053, there was a disturbance 
      in the Force on planet 7. 

的人?

回答

0

我想你回答了你自己的問題......基本上這是一個性能問題。如果slf4j實現被迫查找並解析參數化...以及沒有人願意在日誌系統中使用的開銷。

0

Log4j 2支持slf4j格式,MessageFormat和String.format語法,並支持一組printf方法。