I would like to modify the output printed by System.out.println();
. How is this possible?
It is possible - I've seen it in Bukkit/Craftbukkit. If a plugin is printing a string with System.out.println(String string); Bukkit adds a time/date and logging status to the string.
I would like to do the same like Bukkit.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This question is already answered, however, I would like to add a very good method to trace prints.
Now when you print something, it will show up like "(File:linenumber) text", and in many editors you can just click on that to jump to the location. Its probably quite expensive to get the stacktrace all the time, so probably best to only use it during debug.
You can change the
PrintStream
that is used as the standard output:System.setOut(PrintStream out)
Create your own
PrintStream
implementation which prints whatever extra info you want to the (old) standard output, and set it with:Example:
The following example prints the current time millis before each printed
String
that is printed withPrintStream.println(String x)
method:Output:
Note:
This example only overrides the
PrintStream.println(String x)
method, so calling other print methods ofPrintStream
would not add the time stamp to the output.