If you're really looking for machine-readable log messages, Bunyan is an
elegant solution for NodeJS [1].  I wrote a Java port [2][3][4] - no
connection the the JDK logger, but probably one could write a JDK logger
formatter that would format messages (though it would be ugly and purely by
convention).

It's a particularly simple and elegant approach:  A log message is a single
line of JSON with a few required fields and the rest freeform.  It also
makes it absurdly easy to do things such as create a tiny HTTP server that
lets you stream live log messages and parse and present them prettily in a
browser, or chew on them in other ways.  NodeJS bunyan also comes with some
handy command-line tools for filtering live logs (also useful with curl).

The bottom line on logging is that, once upon the time, Apache had horrible
log files. And everybody looked at that and said "Hey, they have log
files!  Whatever they did must be right".  And an industry evolved around
parsing horrific crap to try to turn it into something useful.  And
everybody's expectations were set that logs were going to be horrible, and
more horrible things had to be invented to parse them.  The JDK's logger is
in that tradition - that's what people thought they wanted.  The best way
to win that entire game is not to play.

Anyway, yes, you could do something with the JDK's logger, or write a
wrapper around it (better), to structure log messages (say, throw key value
pairs into a map and write that as JSON) - what I did for bunyan-java was
use AutoCloseable to let you add key value pairs to a log record on the fly
and flush it on close - it works pretty nicely, since you can capture a
bunch of information about what is happening, failures, etc. in a single
log message as the code does its work:

        try (Log<?> log = downloadLog.info("download")) {
            log.add("cnb", item.codeNameBase())
                    .add("id", id.get())
                    .add("version", item.getVersion())
                    .add("hash", item.hash())
                    .add(evt);
        }


[1] https://github.com/trentm/node-bunyan
[2] https://github.com/timboudreau/bunyan-java
[3]
https://timboudreau.com/builds/job/mastfrog-parent/lastSuccessfulBuild/artifact/bunyan-java/bunyan-java/target/apidocs/index.html
[4] https://timboudreau.com/blog/bunyan/read

On Fri, Mar 15, 2019 at 12:24 AM Arnab Chanda <arnab.cha...@oracle.com>
wrote:

> Hi JT/Geertjan,
>
> This link talks about enabling the logging for NetBeans. I'm looking for a
> netbeans plugin (if it exists) that would actually decorate the code with
> structured logger messages on the source code I'm working on.
>
> For example, there is a plugin in netbeans that allows us to scan the code
> written for possible sonar violations. I'm looking for something similar,
> except that this one would write the logger messages for us too.
>
> Best.
> Arnab
>
> -----Original Message-----
> From: Jaroslav Tulach [mailto:jaroslav.tul...@gmail.com]
> Sent: Thursday, March 14, 2019 10:35 PM
> To: Apache NetBeans
> Subject: Re: Question | Logger | NetBeans plugin
>
> > Does this help:
>
> >
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__bits.netbeans.org_
> > dev_javadoc_org-2Dopenide-2Dutil_org_openide_util_doc-2Dfiles_logging.
> > html&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=D1IHkKGF
> > vzxf_5_uVPbRqKrc_sYohvaaqKm9-IRA5w4&m=nszPclj17EwS1Ks_Nz9KrSfHWXdOQqCa
> > VAR4F_M87G4&s=cDusfSiabzT96MpOjH--WrE3X4IAVUkv2L1CMJ3vjoY&e=
> >
> >
> Right Geertjan, that is the best thing to do. "Using Structured Logging
> for Communication" is the best logging pattern possible with
> java.util.logging infrastructure, in my opinion.
>
> -jt
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@netbeans.incubator.apache.org
> For additional commands, e-mail: dev-h...@netbeans.incubator.apache.org
>
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>
>
>
>

-- 
http://timboudreau.com

Reply via email to