0

We have a java webapp which schedules and runs several other tools in variety of languages /java, perl, bash, python etc.../ and 'eats' their out/err streams using StreamGobblers for troubleshooting purposes;

Is it possible to use log4j /in a core java app/ to log both System.err and System.out so they can be captured in the way described above?

Will this not lead to out and err messages interleaving /appearing out of order/?

Thank you

2 Answers 2

1

Yes. log4j can be used to log to both System.err and System.out in to a separate file/stream.

Yes. The messages can be interleaved.

1
  • @aglassman I just tried it, both out and err are logged to the console /with black and red/ but some messages are out of order. Is there a way to avoid this?
    – John Stadt
    Jun 1, 2012 at 10:08
0

Yes, this is possible. Check out this documentation:

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/ConsoleAppender.html

2
  • Yes, I know I should use or subclass ConsoleAppender but I will need to have 2 - one for out and 1 for err printing to the same stream. I am pretty sure they will interleave at best.
    – John Stadt
    May 31, 2012 at 20:57
  • Log statements shouldn't be interleaved unless you have multiple processes / threads logging to the same log. If possible, you could sort the logs based on date afterwards.
    – aglassman
    Jun 1, 2012 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.