How to remove newline from java logger api?

Here is my code

Logger log = Logger.getLogger("myApp");"hola");


it displays the output as -

Mar 16, 2012 8:58:39 PM *packageName* main 
INFO: hola


I don't want it to create a new line before "INFO" ... how can I tell the logger to do this? I want my output to be like this:

Mar 16, 2012 8:58:39 PM *packageName* main INFO: hola


As with syslog format.


source to share

2 answers

See how to set up Java logging and the documentation on how to specify formatting for SimpleFormatter




Various ways, but here is one. Modify as needed inside publish ().

    Logger log = Logger.getLogger("");
    for (Handler handler :log.getHandlers() ) log.removeHandler(handler);
    log = Logger.getLogger("myLogger");
    log.addHandler(new Handler(){
        public void publish(LogRecord record) {
        public void flush() {
        public void close() throws SecurityException {




All Articles