[Json] Using JSON in log files

Phillip Hallam-Baker <hallam@gmail.com> Wed, 20 November 2013 16:09 UTC

Return-Path: <hallam@gmail.com>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id DD0E71AE022 for <json@ietfa.amsl.com>; Wed, 20 Nov 2013 08:09:42 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.999
X-Spam-Level:
X-Spam-Status: No, score=-1.999 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, SPF_PASS=-0.001] autolearn=ham
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y4WqXDzYER3V for <json@ietfa.amsl.com>; Wed, 20 Nov 2013 08:09:40 -0800 (PST)
Received: from mail-la0-x229.google.com (mail-la0-x229.google.com [IPv6:2a00:1450:4010:c03::229]) by ietfa.amsl.com (Postfix) with ESMTP id 8835D1ADF8E for <json@ietf.org>; Wed, 20 Nov 2013 08:09:40 -0800 (PST)
Received: by mail-la0-f41.google.com with SMTP id eo20so1431397lab.0 for <json@ietf.org>; Wed, 20 Nov 2013 08:09:33 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=/EqykfKXnH+JFQKVZpsucK1Ygoe/HPEmxiXfRhcpUAI=; b=H5UV+LYb4QgKJbA2T52f5PLva453sHEb5suycpAUG5qVdVM8tjaHWIzHr2OIDZzD9e C/XV7cYYiDRhUJLmESIRazBmZBNdy1lWxn1m9dNr7wRdnSQ05UZCRqFz8PDWFsODwOvG oTQabJGgi8dbZWBoCivpaNJZuuDoZxf5MNQ3/e/ylMr7/Ojki31elLz8oPvgO8Boi2xO dRWFY9bHGSdip6V03TuIrFIjNcwWwariuEPin5DiHm9uVO1RKDnRfyapZGaOq0BCDlXF vHcKqYQLY3g6onLAT9QXKmberplnaZrIloi74OFpZ3BVdbdPpw+tK8N8k+v6lIDKNKqT +gnQ==
MIME-Version: 1.0
X-Received: by 10.112.218.39 with SMTP id pd7mr225843lbc.54.1384963773342; Wed, 20 Nov 2013 08:09:33 -0800 (PST)
Received: by 10.112.46.98 with HTTP; Wed, 20 Nov 2013 08:09:33 -0800 (PST)
Date: Wed, 20 Nov 2013 11:09:33 -0500
Message-ID: <CAMm+Lwj49w5qq3V8tLta_GPq3TT5A0FXuKww5RXHbe74dQ5jjA@mail.gmail.com>
From: Phillip Hallam-Baker <hallam@gmail.com>
To: JSON WG <json@ietf.org>
Content-Type: multipart/alternative; boundary="001a11c3cdc8bcab6304eb9e0191"
X-Mailman-Approved-At: Wed, 20 Nov 2013 08:40:13 -0800
Subject: [Json] Using JSON in log files
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 20 Nov 2013 16:09:43 -0000

The biggest technical blunder in JSON right now is the insistence that
there only be one object in a file. XML suffers from the same blunder, here
is why.

If you have a log file and it is being updated by multiple processes, there
is potential for contention between the updates. The simplest mechanism for
resolving that contention is to make the log append only and use some
operating system primitive that supports an atomic write to the end of the
file.

I do have code that allows me to append to the end of a JSON log without
reading the whole thing into memory (which is important as my logs are
expected to grow to several MB.) What I do is to work back from the end of
the file until I see "]}" and then I replace that with ", {<New entry>} ]}

But this approach is rather brittle and somewhat risky. It also upsets
various schemes designed to avoid wearing out my flash memory that handle
atomic append operations in a special way.


What I would like is an option for use in log files only that would allow a
beginning of array marker to inform the reader that the end of file marker
is an implicit close for that structure.

So instead of my file starting:
{
  "Keys": [{
      "KeyID": "AAAJMA-ECEYAJ-GABJYPA-G6AAVC-GAB4ACI-FAAFGA-BGZ2AL-LAA",
      "SelfCertificates": [{

It would look something like:

[*
  {"Key": [{
      "KeyID": "AAAJMA-ECEYAJ-GABJYPA-G6AAVC-GAB4ACI-FAAFGA-BGZ2AL-LAA",
      "SelfCertificates": [{
   ...}
  {...}
  {...}

This is not an extension I would want to use in an on-the-wire format. But
for log files it is essential. Particularly in my case where the logs are
digitally signed notary records.

I will be adding a similar feature to JSON-B but I would if possible like
to make whatever change I make there be compatible with any solutions that
other people have developed independently.


I know this is out of scope for the docs, but I think that adding this
feature and comments to the text encoding of JSON would be useful recharter
items.

And yes, I am aware that some people would prefer to keep JSON simple and
not meet the requirements of my use cases. My position is that I want to
use a single encoding for all the non ASN.1 parts of my system and that be
as close to JSON as possible. But I am not going to compromise my system it
the specification is not adequate for my needs.

Writing a JSON reader is very easy, I am quite OK with a requirement that
someone has to write their own reader or put a wrapper around an existing
reader to accept my logs.

-- 
Website: http://hallambaker.com/