Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

logging

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?

like image 216
black Avatar asked Feb 26 '26 03:02

black


1 Answers

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).

like image 100
halfbit Avatar answered Feb 27 '26 15:02

halfbit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!