Article 5W06X CodeSOD: Leaky Logs

CodeSOD: Leaky Logs

by
Remy Porter
from The Daily WTF on (#5W06X)

For years, Carla's company had a Java application with a memory leak. No one had the time, energy, or budget to actually do anything about the leak, so they "fixed" it by just forcing a nightly reboot.

When Carla asked about the nightly reboot, the elders who had been around for awhile simply said, "there were some issues we couldn't track down."

Carla was assigned a task to go track down some of those untrackable issues. The first thing she discovered was that when she changed the logging level from its production settings to "DEBUG" mode, the application crashed in minutes instead of days. That piece of information sent Carla looking at the logging code to see what was happening.

private static StringWriter logWriter;static { logWriter = new StringWriter(); Layout layout = new PatternLayout(); WriterAppender writerAppender = new WriterAppender(layout, logWriter); writerAppender.setThreshold(Level.DEBUG); writerAppender.activateOptions(); Logger.getRootLogger().addAppender(writerAppender);}

As one might gather from the names, the StringWriter logging just... writes to an in memory string. This code just adds that to the logging chain, ensuring that every log message gets stored in memory, and thus ensuring the application crashes if you leave it running for too long.

otter-icon.png [Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today! TheDailyWtf?d=yIl2AUoC8zA
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments