Quantcast
Viewing latest article 6
Browse Latest Browse All 10

Embrace The Log File

As a programmer how much information are logging to disk about your program’s operation?

If you are like most people, probably very little, maybe none at all. Perhaps you have an exception handling system that logs the pop-up message of unhandled or unexpected errors? That is great, but why not log so much more?

Logging is so cheap nowadays there is no excuse to be conservative! Disk space is incredibly inexpensive and plentiful.

More importantly, the cost of not logging is very expensive: how much time are you willing to spent trying to recreate a scenario in which a bug occurs, just so that you can begin to solve it? Wouldn’t you rather be innovating, instead of firefighting?

There are lots of things you can log, including:

  • Exception messages, with a full stack trace and a screenshot to help identify what was happening at the time
  • All data transmissions; to other databases, EDIs, IPC calls etc.
  • A high-level overview of activity: programs loading, closing, people logging in:
  • Keystrokes and a summary of what was on the screen after each one: great for recreating errors

Even that last log of recording every keystroke and a summary of what was on screen is unlikely to fill up more than 100mb on even the busiest of days.

Scared about the disk space filling up? Use Log Rotate or invent your own script to hook in to the daily backup. We back up the logs and then kill off any log older than a few days. The backups remain for many more days or weeks if we have to delve back in to long term history.

We always log to plain text files which makes them trivial to access. Storing logs in your database or the Windows event log adds time to retrieve them. Every line we log is automatically timestamped to further speed up retrieval of data.

What you will find is that not only bugs are quicker to fix, but you get some great side benefits:

  • You can now track usage of your software; where are users spending the most time?
  • In the event of a program crash, Windows crash, or loss of power, you might have enough information to recreate the transaction that was in progress
  • If a customer asks why or who type questions you have a much better chance of getting an answer, and in a very short period of time

In short: log everything! It’s cheap, easy, and helps you to produce better software!


Viewing latest article 6
Browse Latest Browse All 10

Trending Articles