views:

707

answers:

16

What does your code do to contact you when things go badly wrong?

Actually what i want to know is, How do you get informed by code if something went wrong on your application?

+4  A: 

I get an e-mail to an errors alias (which is filtered from my Inbox). At one point in my career, I would get a text message too, but I think I've chilled out too much to want to be that connected.

JerSchneid
+4  A: 

It depends on the process, and severity/importance of the issue but normally:

  • It writes to a log table
  • It writes to the event log
  • It emails me
  • It SMS's me.
  • A completely seperate process Emails/SMS's a group of people.
Bravax
+1  A: 

What kind of application?

For web sites, I have log4net setup to sent ERROR/FATALS to the Windows event logs, which in turn has a master machine setup to subscribe to various servers logs and send high level things to email/phones based on rules. You could of course have log4net just send those ERR/FATALS to email without the windows event log being involved for small situations.

For applications internet users might use, it's tricker because people generally don't like phone-home code, even when things go wrong.

claco
+8  A: 

In my apps, I have a three layers of protection:

  1. I have general logging at the level INFO which tells me what's going on -- roughly. This is mostly to figure out the timestamp of some event or general issues.

  2. When an log message of level ERROR is written, I go to my cache of log messages. This cache contains the last 200 log messages of any level (TRACE, DEBUG, ...). These 200 are written to an error log. This allows me to debug an issue pretty much by looking at the log.

  3. When a FATAL error is logged, I get an email.

At my current place, I have access to the log directory on the production server. If that's not possible, write your logs to a database.

I'm using log4j, if that matters.

[EDIT] To achieve #2, I wrote a org.apache.log4j.spi.Filter. The filter appends all log messages to a list with a fixed size (when it grows beyond the limit, I'll drop elements from the start). To write the data to a log, create an appender for the filter

This is simple. The tricky part is to install this filter. To do that, you must set the log level of the root logger to TRACE (or at least DEBUG). Here is what the XML config looks like:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/"&gt;

  <appender name="HistoryAppender" class="org.apache.log4j.FileAppender">
    <!-- Level is set by HistoryFilter -->
    <param name="Threshold" value="off" />
    <param name="File" value="tmp/history-test.log" />
    <param name="Append" value="false" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%-5p] [%X{test}] %c{1} - %m%n"/>
    </layout>
  </appender>

  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%-5p] %c{1} - %m%n"/>
    </layout>
    <filter class="ch.globus.basics.log4j.HistoryFilter">
      <param name="HistoryThreshold" value="TRACE" />
      <param name="PassOnThreshold" value="INFO" />
      <param name="Memory" value="200" />
      <param name="Appender" value="HistoryAppender"/>
    </filter>
  </appender>

  <root>
    <level value="DEBUG" />
    <appender-ref ref="HistoryAppender"/>
    <appender-ref ref="ConsoleAppender"/>
  </root>

</log4j:configuration>

As you can see, I'm using the filter in the "real" appender (ConsoleAppender). This is the one which writes the default log file at level INFO (PassOnThreshold). HistoryThreshold specifies the log level of the filter itself (what it will pass on to HistoryAppender). All events above that level will be added to the list. When an ERROR level event is logged, the filter will flush the contents of the list to HistoryAppender.

The main disadvantage is that isDebugLevel() will always return true, so you need to do some fine tuning in the log config to disable logging for noisy stuff like Spring or Hibernate. OTOH, events won't be really logged, just saved in an ArrayList. This takes some time but doesn't kill you unless you're writing StackOverflow ;)

Aaron Digulla
What you describe in 2), is this built into log4j or is it something you've built yourself?
Peter Lillevold
+2  A: 

It doesn't contact me, it write to a log table and emails the application support group.

Nebakanezer
+1  A: 

It sends a bug report (stackdump etc..) with screenshot to our bug database.

Peter Turner
+1  A: 

I use log4Net. For the very touchy error prone Office apps, they write to a central error database. For the more stable web apps, they send me any email.

This normally works pretty well, and I have pretty good response time to the web app bugs. It just sucks the few times some back end database has a problem and then I get hit with 200 emails. However, I think there's a log4Net setting that could correct this if I wanted.

Jacob Adams
+8  A: 

I don't know; nothing has ever gone wrong with my code. :)

D. Patrick
Heh, I got my first 2 downvotes with this one :). That's what I get for tryin' to be funny.
D. Patrick
correction . . . 4 downvotes.
D. Patrick
+1  A: 

We use Hoptoad

DanSingerman
+1  A: 

Usually the rocket engine explodes.... That's a pretty good indicator.

AShelly
A: 

I rewrote Jeff's user-friendly exception handler, so it takes a screenshot, emails us and the helpdesk, and writes to an event log, text file, and the DB.

Chris Doggett
A: 

I am looking at using ELMAH for a new ASP.NET MVC app I am working on. Previously I used log4j and just checked the log once a day.

Chrisb
A: 

When a fatal error happens my code doesn't contact me but it retrieves the latest code from sub version and it automatically fixes itself. It commits the changes to sub version and this code is fully automotically distributed to my customers who never need to know what happened (neither do I).

Once a year a run a report that shows the number of automic fixes.

tuinstoel
Only Jon Skeet could pull such a feat. Which means that you are either an alias or bot of Jon Skeet. But since you don't have enough rep to be any of those, I can safely assume you lie.
Patrick Huizinga
Well, what do they say... "The assumption is the mother of all fuck ups..."
tuinstoel
What a lie.... Sounds too good to be true.
Alec Smart
A: 

I write errors/warnings/info messages with custom numbers for each to the Event Log. We use Microsoft Operations Manager; it picks up on the Event Log entries and reports the error and its number to the person on duty. I have it set up to simply email me warnings, depending on the application.

I supply instructions for each error, such as: "if you see error 10091, the program was unable to connect to the SQL database. Check SQL Server xyz, and contact the dba on duty."

R Ubben
A: 

Anyone seen http://www.exceptioneer.com?

Rob Stevenson-Leggett
A: 

We have the usual logging. Each error gets a reference in the database and a file dump of the all the details (stack trace, etc.). Since the system is only used during extended business hours (7am - 7pm), we only get pager and email notification if an overnight batch fails.

Most general errors result in a relatively friendly message directing the user to contact a help desk with a reference number for the error.

Mike