Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.setOut in a custom format

 
Maikel Geelen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to create a custom format for System.setOut.
I want to write everything that comes in the console to a file. So far i'm able to write to a file but is it possible to put it in a format so i have a more organized log file.



This is what i have to write to the file.




This is my formatter, i've used it before with a filehandler.

Is it possible to use this one here too or is it even possible to create another layout for System.setOut
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I presume that the PrintStream you are using supports the format() and printf() methods, so you can use that format String with those methods.
 
Maikel Geelen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think i would be able to create my layout then.

at the moment my lines in the log file look like this.



And i would like it to look like this




Am i able to use my System.setOut(out) with a FileHandler so i could use TextFormatter
 
Paul Clapham
Sheriff
Posts: 21133
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then just changing where the output goes isn't going to be a solution at all. You actually want to intercept the output and reformat it.

But frankly I wouldn't do that. I would just go through the existing code, find all of the places which use System.out, and modify them to use a proper logging system. (Of which there are plenty, readily available.) Otherwise you'll find yourself writing your own logging system, and rewriting basic Java components is a programming sin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic