0

I found this earlier today and it solved an issue I had very nicely:

Redirect System.out and System.err to slf4j

However, it resulted in another issue: to make this work, I couldn't close stdout and stderr when running my code otherwise I wouldn't get the log messages. This causes an issue when starting the daemon as it locks up the terminal. Hitting Ctrl+C works, but it's not elegent.

So, does anyone know a way where I can capture messages sent to STDOUT or STDERR and still be disconnected from the terminal?

Community
  • 1
  • 1
blockcipher
  • 2,144
  • 4
  • 22
  • 35
  • would you add your code or what you currently have, so we can better help you, please ? – grepit Jun 07 '13 at 17:18
  • Unfortunately, I can't show you my code in it's current form. The relevant code is nothing more than instantiating the logger and using it (E.g. logger.info(...)) plus what is described in that post. – blockcipher Jun 10 '13 at 16:41

1 Answers1

0

O.K. I figured it out. I didn't notice it before, but the code I referenced kept the old streams for System.out and System.err in case the user wanted to revert back to printing to either. Removing that code resolved my issue.

EDIT: Also, had to redirect stdout/stderr to /dev/null with the following at the end of the java command to launch the process:

2>/dev/null 1>&2 &

This appears to be working fine. Hopefully this is useful to someone else in the future.

blockcipher
  • 2,144
  • 4
  • 22
  • 35