Reading and Filtering Eliot Logs

Eliot includes a command-line tool that makes it easier to read JSON-formatted Eliot messages:

$ python examples/ | eliot-prettyprint
  another: 1
  value: hello

  another: 2
  value: goodbye

Run eliot-prettyprint --help to see the various formatting options; you can for example use a more compact one-message-per-line format.

Additionally, the highly recommended third-party eliot-tree tool renders JSON-formatted Eliot messages into a tree visualizing the tasks’ actions.

Filtering logs

Eliot logs are structured, and by default stored in one JSON object per line. That means you can filter them in multiple ways:

  1. Line-oriented tools like grep. You can grep for a particular task’s UUIDs, or for a particular message type (e.g. tracebacks).
  2. JSON-based filtering tools. jq allows you to filter a stream of JSON messages.
  3. eliot-tree has some filtering and searching support built-in.

For example, here’s how you’d extract a particular field with jq:

$ python examples/ | jq '.value'

Parsing Logs

Eliot also includes a parser for parsing logs into Python objects:

import json
from eliot.parse import Parser

def load_messages(logfile_path):
   for line in open(logfile_path):
       yield json.loads(line)

def parse(logfile_path):
    for task in Parser.parse_stream(load_messages(logfile_path)):
        print("Root action type is", task.root().action_type)