The last rule of thumb:
If you're logging the output of a web service or something like that, make sure you log an item which is unique to the session in each log message. With log4j, you can do this using a NDC. (We didn't use the session id, thats too long, we grabbed a unique integer and put it into the session). This way you can trace whats happening to a single session very easily. You can also log the request parameters as well if you're concerned about that sort of thing
for more about NDC, please see: http://lstierneyltd.com/blog/development/log4j-nested-diagnostic-contexts-ndc/ and http://www.vipan.com/htdocs/log4jhelp.html
for code sample:
public ReturnType method( InputType input) throws ExceptionType{
NDC.push("identifyme");
try {
// do something
} catch(ExceptionType e) {
throw e;
} finally {
NDC.pop();
}
}
NDC javadoc here: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html
Hiç yorum yok:
Yorum Gönder