How to continue log on same line in Java?

Leave the log alone. If you want it more readable, post-process it.

Messing with the log file will lose information unless you are careful. Look at timestamps as an example. If your Setting browswer.. log statement has a timestamp included, putting the completed statement without its timestamp is a loss of information and having two timestamps on the same line does not seem natural.


Without knowing precisely which logging library you are using, I would guess that the answer is almost certainly not unless you want to explicitly specify a newline character everywhere else.

The java.util.logging (and Log4J) frameworks allow you to plugin formatters to format your statements. You'd need to specify a format which did not end with a newline character. For example, in Log4J. they give an example pattern as

 %-5p [%t]: %m%n

So if you removed everything except the %m (the %n is the newline and the other stuff includes the time and log-level; %t and %p respectively, I think), newlines would not be automatically appended to each statement.

However, this means that everywhere else, your other log statements would have to look like this:

log.info("I want this on one line\n");