Hi, I wonder if anyone can help me with this before I pull all my hair out !
I have Tomcat5.5 installed as an NT service; and all is working well. I have configured log4j logging for the main server logs (so I have daily rollover etc of catalina.log); and using the properties file, each entry in these logs are date/time stamped nicely.
The other logs that get created are stdout<date>.log and stderr<date>.log These rollover daily, and is out of the box functionality - I've not had to do anything to set these files up. Anything that gets written to stdout and stderr (eg. System.out.println("some text"); ) gets written into these files. Excellent The only problem is that the entries in these files do not get a timestamp
Does anyone know how I can do this ?
(I could change the logging from my application so that it does not use stdout and stderr; or to prefix what I write to stdout/stderr with the current date/time - but thats a lot of code to change, and surely just being able to turn on timestamping for the standard logs will be easier ?)
Thanks in advance
[ July 14, 2006: Message edited by: Nathan Russell ] [ July 14, 2006: Message edited by: Nathan Russell ]
stdout/stderr are not log files. They are bog-standard output streams, and as such, obligated to contain, verbatim, exactly what was written to them, no more, no less.
About the best approximation you could make would be to pass the logs through a filter app that would prefix the text lines. But I make no promises, since depending on buffering, the actual time the text would hit the filter could be significantly delayed. Although usually writing a text line forces a flush all the way out to the filesystem, if one or more layers of buffering get involved, the actual input times to the filter could potentially be days later, when a large buffer flushes out dozens of lines at once.
Lack of timestamps is only one reason why you shouldn't "log" to stdio. J2EE doesn't allow for System.out/System.err. The output to these facilities, either at the server or webapp levels, is unpredictable. It can go anywhere or nowhere, and, in fact, I've see Tomcat target 2 entirely different destinations depending on whether it was running under Solaris or under Windows. I'll admit sometimes I cheat while developing for an occasional quick-and-dirty display above and beyond what the debugger supplies, but I convert to true logging long before I move to production.
You can actually do a fairly straightforward search-and-replace on source code stdio calls, converting "System.out.println" to "log.info", and "System.err.println" to "log.severe". That still leaves the need to define the loggers themselves (I have a command key in my IDE to do that). And, of course, if you do "print"s instead of "println"s, that requires some manual review.
Customer surveys are for companies who didn't pay proper attention to begin with.