 options.lines or= 4
 options.output or= "text"
 
+readExceptions = (stderr, exceptions) ->
+  # Split stderr into lines and pop the last blank line.
+  stderr = stderr.split("\n")
+  stderr.pop()
+
+  # Read the stack backwards popping the all the stack lines and the blank line
+  # before the stack.
+  stack = []
+  while stderr.length and match = /^\s{4}at\s(\S+)\s+\(([^:]+):(\d+):(\d+)\)$/.exec(stderr[stderr.length - 1])
+    [ method, file, line, column ] = match.slice(1)
+    stack.unshift { method, file, line, column }
+    stderr.pop()
+
+  # If we have a stack, then we have an exception.
+  if stack.length
+    # Pull the location display off the top of the lines, if it exists.
+    if stderr.length >= 4 and stderr[0] is "" and (location = /^(.*):(\d+)$/.exec(stderr[1])) and (column = /^(\s*)\^$/.exec(stderr[3]))
+      snippet =
+        file: location[1]
+        text: stderr[2]
+        line: parseInt(location[2], 10)
+        column: column[1].length + 1
+      stderr = stderr.slice(4)
+
+    # Read any JSON output, if it exists.
+    json = []
+    if /^\s{4}}/.test(stderr[stderr.length - 2])
+      while not /^\s{4}{$/.test(line = stderr.pop())
+        json.unshift line
+      json.unshift line
+      json = json.join "\n"
+      stderr.pop()
+
+    # What remains is the exception message. 
+    message = stderr.join "\n"
+
+    # Build the exception record.
+    exception = { message, stack }
+    if json.length
+      try
+        exception.json = JSON.parse(json)
+      catch e
+        exception.json = json
+        exception.jsonInvalid = true
+    exception.location = snippet if snippet
+
+    exceptions.push exception
+    if exception.json and exception.json.stderr
+      readExceptions(exception.json.stderr, exceptions)
+
 readBuffer = (buffer, end, contents, output, callback) ->
   chunkSize = 1024 * 2
   offset = end - chunkSize

      readBuffer buffer, read, contents, output, ->
        readLog fd, buffer, contents, size - read, output, callback

fs.open "/var/log/messages", "r", (error, fd) ->
  throw error if error
  buffer = new Buffer(1024 * 1024 * 64)

          record.json = json
          record.jsonInvalid = true
        if record.json.stderr
          exceptions = []
          readExceptions(record.json.stderr, exceptions)
          record.exceptions = exceptions if exceptions.length > 0 

      output.unshift record
  if offset > 0 and output.length < options.lines
