Re: Patch Suggestion
Michael B Allen <[email protected]>
| Newsgroups | gmane.network.samba.java |
|---|---|
| Message-ID | <CAGMFw4iKs56Ww0=80m9j_gdS1O2TtqsVSEKPHgL9=z+4NitXnQ@mail.gmail.com> |
On Mon, Apr 30, 2012 at 1:07 PM, Hardy Cherry <[email protected]> wrote: > We are investigating the use of jCIFS in one of our products. To monitor our error logs we use splunk which depends on each log having a timestamp. > Would it be possible to format the logs jCIFS creates so that they have a time stamp? > > Here is my suggested change to the LogStream class: > Add an overrided version of println() > > @Override > public void println(String x) > { > String newLine = System.getProperty("line.separator"); > //Format the error before printing it. Will look like this > //Mon Apr 30 04:06:05 MDT 2012 > // Source: jCIFS Error Logging > // ERROR: x > super.println(new java.util.Date().toString() + newLine + " Source: jCIFS Error Logging " + newLine + " ERROR: " + x); > } Hi Hardy, A patch is not necessary. Just extend the log stream class, override both println methods as desired and then install it with LogStream.setInstance(). But multiple lines for each entry is probably not what you want. A proper implementation would probably look something like: class TimestampedLogStream extends jcifs.util.LogStream { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); TimestampedLogStream(OutputStream out) { super(out); } public void println(Object o) { synchronized (sdf) { super.println(sdf.format(new Date()) + ": " + o); } } public void println(String s) { synchronized (sdf) { super.println(sdf.format(new Date()) + ": " + s); } And then install this early in your program somewhere with a statement like: jcifs.util.LogStream.setInstance(new TimestampedLogStream(System.err)); Mike -- Michael B Allen Java Active Directory Integration http://www.ioplex.com/