Logging as Event Streams

Paul Querna
June 27, 2012

Why I care about Logging

Application vs System Logging

Motivation: Logging Meets "Cloud"

Logging is an Event Emitter

logging.error('Something is wrong');
emit('log', {level: 'error', msg: 'Something is wrong'});

There is no difference here.

Structured Logging

Why Structured Logging?

Structured Logging: JSON?

HTTP Example

{
    "timestamp": 1324830675.076,
    "status": "404",
    "short_message": "File does not exist: /var/www/no-such-file",
    "host": "ord1.product.api0",
    "facility": "httpd",
    "errno": "ENOENT",
    "remote_host": "50.57.61.4",
    "remote_port": "40100",
    "path": "/var/www/no-such-file",
    "uri": "/no-such-file",
    "level": 4,
    "headers": {
        "user-agent": "BadAgent/1.0",
        "connection": "close",
        "accept": "*/*"
    },
    "method": "GET",
    "unique_id": ".rh-g2Tm.h-ord1.product.api0.r-axAIO3bO.c-9210.ts-1324830675.v-24e946e"
}

CLF vs JSON


Perl Cookbook says:
my ($client, $identuser, $authuser, $date, $time, $tz, $method,
    $url, $protocol, $status, $bytes) =
/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] "(\S+) (.*?) (\S+)"
    (\S+) (\S+)$/;
$msg = JSON->decode($json_text);
  • Now a developer adds a new field.

Elements of Every Log Message

Message Tags / IDs

Trace IDs

Trace IDs

Trace IDs

.rh-el1U.h-ord1-maas-prod-api0.
r-tvTCwfS3.c-33110.ts-1340775011499.v-c76a8c29

Trace IDs: Twitter Zipkin


Shipping Logs: Goals

svlogd, & Scribe.

Shipping Logs between machines

Scribe

Scribe Setup


Graylog2

Graylog2 Streams


Graylog2 Tracing


Graylog2 Message Permalink


Detour: Audit Logs of HTTP APIs

Detour: Audit Logs of HTTP APIs

"values": [
{
  "id": "541615e0-bee4-11e1-a3c9-69984867fc3c",
  "timestamp": 1340642367038,
  "method": "POST",
  "url": "/v1.0/626873/entities/entMvVW47r/test-check",
  "app": "checks",
  "query": {},
  "txnId": ".rh-TL0q.h-ord1-maas-prod-api0.r-8NQS2mx5.c-280514.ts-1340642366874.v-1a7152ba29615a722a2713bef4d4fe2b5c6ee7ae",
  "payload": "{\"target_hostname\":\"www.example.com\",\"type\":\"remote.http\",\"details\":{},\"monitoring_zones_poll\":[\"mzord\",\"mzdfw\",\"mzlon\"]}",
  "account_id": "626873",
  "headers": {
      "host": "monitoring.api.rackspacecloud.com",
      "accept-encoding": "gzip,deflate",
      "content-type": "application/json; charset=UTF-8",
      "accept": "application/json",
      "user-agent": "libcloud/0.10.1 (Rackspace Monitoring)",
      "content-length": "140"
  },
  "statusCode": 400
},

Thank You & Questions


paul.querna.org/slides


Links: