I've been working on some web applications that make heavy use of printStackTrace(), or System.err.println(...) for error messages.
Is this common in real programs? I've found it difficult to work with because all messages go to the same file without any date/time or usernames so it's difficult to tell which messages go together or where they come from. These files also fill up with junk/debugging output which make it difficult to find important information in them.
There seems to be many different logging libraries for Java. Would SLF4J work well? It seems to have compatibility with some of the other libraries so it looks quite flexible. I would probably use Logback or Log4J along with it.
Does anyone use the Mapped Diagnostic Context features of these libraries? Adding username and ip addresses to the messages would be useful. Anything else?
Also, how would you view the log files? Do you log to a database, or use any specific programs?
log4j used to be quite popular, and may still be the most widely used library. These days, I'm seeing a shift towards using slf4j, and then either java.util.logging or log4j underneath it. I think logging to files is still more widely done than logging to a DB; it depends on how you intend to use the logs later, though.
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad: