Re: [Json] Using JSON in log files

Tatu Saloranta <tsaloranta@gmail.com> Wed, 20 November 2013 18:22 UTC

Return-Path: <tsaloranta@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 273551AE505 for <json@ietfa.amsl.com>; Wed, 20 Nov 2013 10:22:33 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.399
X-Spam-Level:
X-Spam-Status: No, score=-1.399 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, J_CHICKENPOX_34=0.6, SPF_PASS=-0.001] autolearn=no
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 B6NKTX41gNTz for <json@ietfa.amsl.com>; Wed, 20 Nov 2013 10:22:31 -0800 (PST)
Received: from mail-wg0-x22e.google.com (mail-wg0-x22e.google.com [IPv6:2a00:1450:400c:c00::22e]) by ietfa.amsl.com (Postfix) with ESMTP id 1D67E1AE0D8 for <json@ietf.org>; Wed, 20 Nov 2013 10:22:30 -0800 (PST)
Received: by mail-wg0-f46.google.com with SMTP id x12so9353767wgg.1 for <json@ietf.org>; Wed, 20 Nov 2013 10:22:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=JB4xun/qZJM0mh15zotfcVWCyLCPo3Lx8V8ug8h2AIE=; b=C1zs0ft2AKBYI0J2xLdkl5FbN157kiVJpAA2yUqCF4vqKUiLWfztGBF+QgsuKE/tYj KPdiW75frHecKyf3mo9jiKIyD1z/4muGGozlfhDrujKGDY2SA1M8zgf641GyofPeWr5o kvYjk28MOHvlPJLA5xlaHHtEXD+ebXQ+iYT/EG1JrT13YnAIuGXKSKq7RiOXI+gTdiAt W8sz55ICcHEgeScJzCa3zIzjazQQCew/2MjKKg+iAXSaYtA+5ljEluXJdIV4eUOMxdxT knNynkiZXhkxUFmwZAMYQ7jh2i31tXBVsAIMzjtBYnKT0TFvdFpzmc4KlYLdFSAPMTEU sSRw==
MIME-Version: 1.0
X-Received: by 10.180.210.134 with SMTP id mu6mr26559260wic.37.1384971744208; Wed, 20 Nov 2013 10:22:24 -0800 (PST)
Received: by 10.227.61.195 with HTTP; Wed, 20 Nov 2013 10:22:24 -0800 (PST)
In-Reply-To: <CAMm+Lwj49w5qq3V8tLta_GPq3TT5A0FXuKww5RXHbe74dQ5jjA@mail.gmail.com>
References: <CAMm+Lwj49w5qq3V8tLta_GPq3TT5A0FXuKww5RXHbe74dQ5jjA@mail.gmail.com>
Date: Wed, 20 Nov 2013 10:22:24 -0800
Message-ID: <CAGrxA26qXDve-fhW2zG8jHeiwFvaVrJ9WBa=e83yQ1mLqKVDrA@mail.gmail.com>
From: Tatu Saloranta <tsaloranta@gmail.com>
To: Phillip Hallam-Baker <hallam@gmail.com>
Content-Type: multipart/alternative; boundary="001a11c37bdcd66c1804eb9fdc54"
Cc: JSON WG <json@ietf.org>
Subject: Re: [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 18:22:33 -0000

This is one of canonical use-cases for streaming JSON processing: just use
linefeed between root-level values. Many/most streaming JSON readers
support this, especially Java ones (Jackson definitely does; GSON has
streaming mode, Genson as well; org.json's toy lib should not be used for
anything).
It also makes it easier to read, should you need to check out log files.

Or, if you want to be strictly compliant with specs, use a container JSON
array.
Streaming readers (and generators) should work fine here as well.
There is no need to buffer the whole log stream in buffer either when
reading or writing.

-+ Tatu +-



On Wed, Nov 20, 2013 at 8:09 AM, Phillip Hallam-Baker <hallam@gmail.com>wrote:

> 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/
>
> _______________________________________________
> json mailing list
> json@ietf.org
> https://www.ietf.org/mailman/listinfo/json
>
>