I have an application written in Java and slf4j-logback for logging. There is so many System.out.println() statements in the application. Is there any way to write all the sysout output to separate log file using logback.
Asked
Active
Viewed 1,640 times
-1
-
possible duplicate of https://stackoverflow.com/questions/637827/redirect-stderr-and-stdout-in-bash/637839 – Scary Wombat Aug 02 '18 at 06:15
-
Conceptually, something [like this](https://stackoverflow.com/questions/12945537/how-to-set-output-stream-to-textarea/12945678#12945678) and [like this](https://stackoverflow.com/questions/22241024/system-out-println-redirection-in-java/22241169#22241169) – MadProgrammer Aug 02 '18 at 06:17
2 Answers
1
Please run the application from your console / command prompt and redirect the output to a file.
For eg HelloWorld is your class. All prints will be redirected to hello.txt file.
java HelloWorld >> hello.txt

Sai Kandukuri
- 41
- 1
- 3
0
System.setOut(new PrintStream(new File(path/to/yourfile)));

thunderfury
- 1
- 1
-
While technically create, it's a good idea to to continue to print to the stdout AS well as the file, it's a little complicated, but achievable ;) – MadProgrammer Aug 02 '18 at 06:18
-
-
2While this code may answer the question, providing additional context regarding *how* and/or *why* it solves the problem would improve the answer's long-term value. See [this meta post](https://meta.stackoverflow.com/questions/300837). – user202729 Aug 02 '18 at 06:59