Skip to content

adds support for logback encoders (the message field is encoded). - #794

Merged
bruno-garcia merged 1 commit into
getsentry:masterfrom
jeacott1:logback-appender-mod
Nov 28, 2019
Merged

adds support for logback encoders (the message field is encoded).#794
bruno-garcia merged 1 commit into
getsentry:masterfrom
jeacott1:logback-appender-mod

Conversation

@jeacott1

@jeacott1 jeacott1 commented Nov 18, 2019

Copy link
Copy Markdown

adds support for logback encoders (the message field is encoded)
adds support for global tags and extras (not threadbound). tags and extras are
distinguished by the existing mdcTags property.

basic usage:
encoders

    <appender name="jsonSentryAppender" class="io.sentry.logback.SentryAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
        <encoder
            class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
           <providers>
               <timestamp />
                <version />
                <logLevel />
                ...

basic usage:
global entries as tags or extras

  LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
  context.putProperty("global", "value");

@jeacott1
jeacott1 force-pushed the logback-appender-mod branch 4 times, most recently from eaa118f to cafb55b Compare November 18, 2019 23:12
adds support for global tags and extras. tags and extras are
 distinguished by the existing mdcTags property.

basic usage:
encoders

```
    <appender name="jsonSentryAppender" class="io.sentry.logback.SentryAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
        <encoder
            class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
           <providers>
               <timestamp />
                <version />
                <logLevel />
                ...
...
```

basic usage:
global entries as tags or extras

```

  LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
  context.putProperty("global", "value");

```

@metlos metlos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, apart from the one nitpick.

/**
* Appender encoder.
*/
protected Encoder<ILoggingEvent> encoder;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be at least AtomicReference and CAS'd on the use sites so that the unsynchronized access is somewhat handled? Or is it only ever supposed to be mutated by logback during instantiation and before any logging can occur?

@jeacott1 jeacott1 Nov 26, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I understand it this isn't an issue. And yes, I think you'd typically create and replace with a new appender than dynamically replace an encoder.

fyi fwiw logstashencoder is doing the same thing:
https://github.com/logstash/logstash-logback-encoder/blob/bbd8333120f274f4d9ef12e797eae2331fed1a52/src/main/java/net/logstash/logback/appender/AbstractLogstashTcpSocketAppender.java#L199

@bruno-garcia
bruno-garcia merged commit aaad367 into getsentry:master Nov 28, 2019
@bruno-garcia

Copy link
Copy Markdown
Member

Thank you @jeacott1

@jeacott1

Copy link
Copy Markdown
Author

should probably add something to the documentation too at some point :)

@bruno-garcia

Copy link
Copy Markdown
Member

@jeacott1

Copy link
Copy Markdown
Author

sure!

@bruno-garcia

Copy link
Copy Markdown
Member

Thank you @jeacott1

@jeacott1

Copy link
Copy Markdown
Author

please check getsentry/sentry-docs#1379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants