For better or for worse (worse I suspect) we have a third-party API we’re integrating to using Flow and Java Services in IS61. The API writes warning and error messages to the console using System.out and System.err. Since we’re running IS as a service on a Windows box, the output isn’t captured.
I’ve written a quick and dirty Java service to re-direct stderr and stdout using the webMethods ServerAPI.getLogStream() method. The object it returns (LogOutputStream) isn’t documented in the webMethods API documentation, so I thought I’d see if anyone had some exposure to it. It seems to work well, and as a bonus the logs roll themselves over daily.
EDIT: Since the log files roll-over automatically, I don’t really need the date in the filename; it becomes redundant after the rollover (i.e. ‘systemout20071003.log’ becomes ‘systemout20071003.200710030000.log’).
Advice? Opinions? Flames?
[size=-1] static final String sysOutPrefix = "systemout"; static final String sysErrPrefix = "systemerr"; static final String logfileSuffix = ".log"; String errFile = ""; String outFile = ""; String currentDate = ""; currentDate = (new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date())); outFile = sysOutPrefix + currentDate + logfileSuffix; errFile = sysErrPrefix + currentDate + logfileSuffix; LogOutputStream wmSysOutStream = null; LogOutputStream wmSysErrStream = null; PrintStream sysOutPrintStream = null; PrintStream sysErrPrintStream = null; wmSysOutStream = ServerAPI.getLogStream(outFile); wmSysErrStream = ServerAPI.getLogStream(errFile); sysOutPrintStream = new PrintStream(wmSysOutStream, true); sysErrPrintStream = new PrintStream(wmSysErrStream, true);[/size] [size=-1] System.setOut(sysOutPrintStream); System.setErr(sysErrPrintStream); [/size]