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

John Stadt
  • 500
  • 7
  • 17

2 Answers2

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.

Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94
  • @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 01 '12 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

aglassman
  • 2,643
  • 1
  • 17
  • 30
  • 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 '12 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 01 '12 at 14:13