Java java.util.logging.logger. Using array objects as arguments

£可爱£侵袭症+ 提交于 2020-01-04 07:17:50

问题


java.util.logging.Logger class provides ability to use such a syntax:

int i=0;
log.log(Level.INFO,"int i = {0}", i);

This will print out "int i = 0". Unfortunately when I have a bigger value, like 9093, it will print out "int i= 9,023" separating each 3 digits with comma.

The question is how should I get rid of thoose commas? Preferably changing insides of {}. Tried both {0:d} and {0:%d}. Both didnt help. Is it even possible to control parametres like this? Or should I convert my int to string myself?


回答1:


It seems the second parameter is a MessageFormat which supports "sub-formats". Try

log.log(Level.INFO, "int i = {0,number,#}", 1234567);

This eliminates grouping characters for me.

See http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html and http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html (number sub-formats are interpreted as DecimalFormat).



来源:https://stackoverflow.com/questions/20749130/java-java-util-logging-logger-using-array-objects-as-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!