You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Raman Gupta <ro...@gmail.com> on 2021/06/30 22:09:44 UTC

JsonTemplateLayout for Google Cloud Logging

I was thinking about contributing a JsonTemplateLayout for the structured logging format expected by Google Cloud Logging [1].

This is what I've come up with so far: any comments are welcome: https://gist.github.com/rocketraman/824ca9527bb8c7226d40db2b4d78efa7.

[1] https://cloud.google.com/logging/docs/structured-logging

Regards,
Raman


Re: JsonTemplateLayout for Google Cloud Logging

Posted by Matt Sicker <bo...@gmail.com>.
Looks like a nifty feature!

On Wed, Jun 30, 2021 at 5:09 PM Raman Gupta <ro...@gmail.com> wrote:
>
> I was thinking about contributing a JsonTemplateLayout for the structured logging format expected by Google Cloud Logging [1].
>
> This is what I've come up with so far: any comments are welcome: https://gist.github.com/rocketraman/824ca9527bb8c7226d40db2b4d78efa7.
>
> [1] https://cloud.google.com/logging/docs/structured-logging
>
> Regards,
> Raman
>

Re: JsonTemplateLayout for Google Cloud Logging

Posted by Matt Sicker <bo...@gmail.com>.
As a committer, yes, feel free to use the dev field. The due-to field
is used for contributions from outside the project.

On Thu, Jul 1, 2021 at 4:48 PM Raman Gupta <ro...@gmail.com> wrote:
>
> FYI:
>
> https://issues.apache.org/jira/browse/LOG4J2-3116
>
> https://github.com/apache/logging-log4j2/pull/543
>
> One administrative note -- as I am a committer (although thus far I have
> only committed to the log4j2 kotlin repo) should I do dev="rgupta" instead
> of adding myself in due-to?
>
> Some technical notes -- some of the functionality could be more efficient
> with some changes to the resolvers, to avoid delegating so many of the
> fields to the pattern resolver. Specifically:
>
> 1) the level resolver could be enhanced with a label mapping function,
> 2) the message resolver could optionally output stack trace as well, and
> 3) a serial number resolver could be added.
>
> However, in my opinion we should commit the basic functionality first, and
> deal with those sorts of optimizations later.
>
> Regards,
> Raman
>
>
>
> On Thu, Jul 1, 2021 at 3:06 PM Volkan Yazıcı <vo...@gmail.com>
> wrote:
>
> > That is a great idea Raman! Would you mind creating a PR along with a Jira
> > ticket, please? I would appreciate if you can take the following into
> > account:
> >
> >    - Target release-2.x branch for the PR
> >    - Prefix the PR title with the Jira ticket id
> >    - Update json-template-layout.adoc.vm (See the "predefined event
> >    templates" paragraph there.)
> >    - Update changes.xml (... dev="vy" ... due-to="Raman Gupta")
> >    - Put the file to
> >    log4j-layout-template-json/src/main/resources/GcpLoggingLayout.json
> >
> > Kind regards.
> >
> > On Thu, Jul 1, 2021 at 12:09 AM Raman Gupta <ro...@gmail.com> wrote:
> >
> > > I was thinking about contributing a JsonTemplateLayout for the structured
> > > logging format expected by Google Cloud Logging [1].
> > >
> > > This is what I've come up with so far: any comments are welcome:
> > > https://gist.github.com/rocketraman/824ca9527bb8c7226d40db2b4d78efa7.
> > >
> > > [1] https://cloud.google.com/logging/docs/structured-logging
> > >
> > > Regards,
> > > Raman
> > >
> > >
> >

Re: JsonTemplateLayout for Google Cloud Logging

Posted by Raman Gupta <ro...@gmail.com>.
On Sun, Jul 4, 2021 at 2:59 PM Volkan Yazıcı <vo...@gmail.com>
wrote:

> *[My answers are inline.]*
>
> On Thu, Jul 1, 2021 at 11:48 PM Raman Gupta <ro...@gmail.com> wrote:
>
> >
> > https://issues.apache.org/jira/browse/LOG4J2-3116
> > https://github.com/apache/logging-log4j2/pull/543
> >
>
> Thanks! I will check these out momentarily.
>
>
I'm having one issue with the tests, and replied to your comment in the
pull.


>
> > One administrative note -- as I am a committer (although thus far I have
> > only committed to the log4j2 kotlin repo) should I do dev="rgupta"
> instead
> > of adding myself in due-to?
> >
>
> Of course! Apologies that I have totally missed it.
>
> Some technical notes -- some of the functionality could be more efficient
> > with some changes to the resolvers, to avoid delegating so many of the
> > fields to the pattern resolver. Specifically:
> >
> > 1) the level resolver could be enhanced with a label mapping function,
> >
>
> PatternLayout enhances individual resolvers. For instance, %level directive
> accepts a boolean lowerCase argument. In JsonTemplateLayout, I want to
> follow a different approach and rather than enhancing individual resolvers,
> I want to introduce reusable components. For instance, I have recently
> introduced the CaseConverter resolver. One can combine this with
> LevelResolver to have the same effect with %level{lowerCase} in
> PatternLayout. Coming back to your remark about LevelResolver, similarly,
> rather than enhancing LevelResolver, I want to introduce a
> SubstitutionResolver, if you know what I mean. Nevertheless, please go
> ahead and create a ticket addressing your "problem". I can comment further
> there on how to approach it.
>
>
I was wondering if I could combine resolvers, but I didn't see any
documentation or examples showing that. Thanks for confirming that is your
preferred approach to the problem.

Issue for SubstitutionResolver:
https://issues.apache.org/jira/browse/LOG4J2-3119


>
> > 2) the message resolver could optionally output stack trace as well, and
> >
>
> Again, similar to the aforementioned "reusable components" strategy, I was
> thinking of creating a ConcatenationResolver. Would you mind creating a
> ticket for this as well, please?
>
>
https://issues.apache.org/jira/browse/LOG4J2-3120


>
> > 3) a serial number resolver could be added.
> >
>
> Do you mean as the one mentioned in LOG4J2-3067
> <https://issues.apache.org/jira/browse/LOG4J2-3067>?
>
>
Yes


>
> > However, in my opinion we should commit the basic functionality first,
> and
> > deal with those sorts of optimizations later.
> >
>
> Agreed! This said, let's create tickets for these feature requests so as
> not to forget them.
>

Done, see above.

Re: JsonTemplateLayout for Google Cloud Logging

Posted by Volkan Yazıcı <vo...@gmail.com>.
*[My answers are inline.]*

On Thu, Jul 1, 2021 at 11:48 PM Raman Gupta <ro...@gmail.com> wrote:

>
> https://issues.apache.org/jira/browse/LOG4J2-3116
> https://github.com/apache/logging-log4j2/pull/543
>

Thanks! I will check these out momentarily.


> One administrative note -- as I am a committer (although thus far I have
> only committed to the log4j2 kotlin repo) should I do dev="rgupta" instead
> of adding myself in due-to?
>

Of course! Apologies that I have totally missed it.

Some technical notes -- some of the functionality could be more efficient
> with some changes to the resolvers, to avoid delegating so many of the
> fields to the pattern resolver. Specifically:
>
> 1) the level resolver could be enhanced with a label mapping function,
>

PatternLayout enhances individual resolvers. For instance, %level directive
accepts a boolean lowerCase argument. In JsonTemplateLayout, I want to
follow a different approach and rather than enhancing individual resolvers,
I want to introduce reusable components. For instance, I have recently
introduced the CaseConverter resolver. One can combine this with
LevelResolver to have the same effect with %level{lowerCase} in
PatternLayout. Coming back to your remark about LevelResolver, similarly,
rather than enhancing LevelResolver, I want to introduce a
SubstitutionResolver, if you know what I mean. Nevertheless, please go
ahead and create a ticket addressing your "problem". I can comment further
there on how to approach it.


> 2) the message resolver could optionally output stack trace as well, and
>

Again, similar to the aforementioned "reusable components" strategy, I was
thinking of creating a ConcatenationResolver. Would you mind creating a
ticket for this as well, please?


> 3) a serial number resolver could be added.
>

Do you mean as the one mentioned in LOG4J2-3067
<https://issues.apache.org/jira/browse/LOG4J2-3067>?


> However, in my opinion we should commit the basic functionality first, and
> deal with those sorts of optimizations later.
>

Agreed! This said, let's create tickets for these feature requests so as
not to forget them.

Re: JsonTemplateLayout for Google Cloud Logging

Posted by Raman Gupta <ro...@gmail.com>.
FYI:

https://issues.apache.org/jira/browse/LOG4J2-3116

https://github.com/apache/logging-log4j2/pull/543

One administrative note -- as I am a committer (although thus far I have
only committed to the log4j2 kotlin repo) should I do dev="rgupta" instead
of adding myself in due-to?

Some technical notes -- some of the functionality could be more efficient
with some changes to the resolvers, to avoid delegating so many of the
fields to the pattern resolver. Specifically:

1) the level resolver could be enhanced with a label mapping function,
2) the message resolver could optionally output stack trace as well, and
3) a serial number resolver could be added.

However, in my opinion we should commit the basic functionality first, and
deal with those sorts of optimizations later.

Regards,
Raman



On Thu, Jul 1, 2021 at 3:06 PM Volkan Yazıcı <vo...@gmail.com>
wrote:

> That is a great idea Raman! Would you mind creating a PR along with a Jira
> ticket, please? I would appreciate if you can take the following into
> account:
>
>    - Target release-2.x branch for the PR
>    - Prefix the PR title with the Jira ticket id
>    - Update json-template-layout.adoc.vm (See the "predefined event
>    templates" paragraph there.)
>    - Update changes.xml (... dev="vy" ... due-to="Raman Gupta")
>    - Put the file to
>    log4j-layout-template-json/src/main/resources/GcpLoggingLayout.json
>
> Kind regards.
>
> On Thu, Jul 1, 2021 at 12:09 AM Raman Gupta <ro...@gmail.com> wrote:
>
> > I was thinking about contributing a JsonTemplateLayout for the structured
> > logging format expected by Google Cloud Logging [1].
> >
> > This is what I've come up with so far: any comments are welcome:
> > https://gist.github.com/rocketraman/824ca9527bb8c7226d40db2b4d78efa7.
> >
> > [1] https://cloud.google.com/logging/docs/structured-logging
> >
> > Regards,
> > Raman
> >
> >
>

Re: JsonTemplateLayout for Google Cloud Logging

Posted by Volkan Yazıcı <vo...@gmail.com>.
That is a great idea Raman! Would you mind creating a PR along with a Jira
ticket, please? I would appreciate if you can take the following into
account:

   - Target release-2.x branch for the PR
   - Prefix the PR title with the Jira ticket id
   - Update json-template-layout.adoc.vm (See the "predefined event
   templates" paragraph there.)
   - Update changes.xml (... dev="vy" ... due-to="Raman Gupta")
   - Put the file to
   log4j-layout-template-json/src/main/resources/GcpLoggingLayout.json

Kind regards.

On Thu, Jul 1, 2021 at 12:09 AM Raman Gupta <ro...@gmail.com> wrote:

> I was thinking about contributing a JsonTemplateLayout for the structured
> logging format expected by Google Cloud Logging [1].
>
> This is what I've come up with so far: any comments are welcome:
> https://gist.github.com/rocketraman/824ca9527bb8c7226d40db2b4d78efa7.
>
> [1] https://cloud.google.com/logging/docs/structured-logging
>
> Regards,
> Raman
>
>