I've added some basic JSON support to Chainsaw:
https://github.com/apache/logging-chainsaw/pull/9
It is a little funny to work with though, because of how Chainsaw
works it is tightly tied to Log4j1 messages, so all we're really doing
is extracting the parts that we care about and putting it into the
Log4j1 format.

This does require adding a new dependency to parse JSON(Genson), but
that is Apache licensed.

-Robert Middleton

On Sat, Jun 19, 2021 at 6:29 AM Volkan Yazıcı <volkan.yaz...@gmail.com> wrote:
>
> For the records, JsonTemplateLayout also quotes all escape characters,
> including CR and LF characters, in every(!) string value. For instance, the
> following test succeeds:
>
> String eventTemplate = writeJson(asMap(
>     "epochSecs", asMap(
>             "$resolver", "exception",
>             "field", "stackTrace",
>             "stackTrace", asMap(
>                     "stringified", true))));
> JsonTemplateLayout layout = JsonTemplateLayout
>         .newBuilder()
>         .setConfiguration(CONFIGURATION)
>         .setEventTemplate(eventTemplate)
>         .setEventDelimiter("")
>         .build();
> LogEvent logEvent = Log4jLogEvent
>         .newBuilder()
>         .setLoggerName(LOGGER_NAME)
>         .setThrown(new RuntimeException())
>         .build();
> String serializedLogEvent = layout.toSerializable(logEvent);
> assertThat(serializedLogEvent).doesNotContain("\n");
>
> Hence, newlines in stack traces or whatever input string there is to be
> encoded to JSON, are not a problem for JsonTemplateLayout.
>
> On Fri, Jun 18, 2021 at 7:49 PM Ralph Goers <ralph.go...@dslextreme.com>
> wrote:
>
> >
> >
> > > On Jun 18, 2021, at 10:40 AM, Matt Sicker <boa...@gmail.com> wrote:
> > >
> > > A couple other common log collection setups I've come across over time:
> > >
> > > * Logging to stdout/stderr in a standard format, then use a log
> > > collection API from your orchestration engine (common in the
> > > Kubernetes world to avoid logging to a file).
> >
> > NOT recommended for use with Log4j. See
> > http://logging.apache.org/log4j/2.x/manual/cloud.html.
> >
> > > * Logging to a log file as normal, but running a log forwarding agent
> > > alongside (e.g., Splunk, Logstash).
> > > * Logging to syslog (typically more important for auditing and
> > > security related logs)
> > >
> > > For the log format itself, JSON template layouts work great here for
> > > customizing how much info you need in your logs. It also makes it much
> > > easier to create log indices in various log searching products. Which
> > > particular one hasn't been as important in my experience as trying to
> > > stay consistent.
> > >
> >
> > I happen to like GELF as it neatly solves the problem of Java Exceptions
> > having newlines in them. Other formats that use the newline to delimit the
> > end of the message require weird rules to be set up in Logstash to glue
> > the various lines back together again. Invariably some message will
> > violate
> > the assumptions the rules are based on.
> >
> > Ralph
> >
> >
> >

Reply via email to