1111import io .sentry .core .SentryOptions ;
1212import io .sentry .core .protocol .Message ;
1313import io .sentry .core .protocol .SdkVersion ;
14-
14+ import io .sentry .core .transport .ITransport ;
15+ import io .sentry .core .util .CollectionUtils ;
1516import java .util .Arrays ;
1617import java .util .Collections ;
1718import java .util .Date ;
2021import java .util .Objects ;
2122import java .util .Optional ;
2223import java .util .stream .Collectors ;
23-
24- import io .sentry .core .transport .ITransport ;
25- import io .sentry .core .util .CollectionUtils ;
2624import org .jetbrains .annotations .ApiStatus ;
2725import org .jetbrains .annotations .NotNull ;
2826import org .jetbrains .annotations .Nullable ;
2927
3028/** Appender for logback in charge of sending the logged events to a Sentry server. */
3129public final class SentryAppender extends UnsynchronizedAppenderBase <ILoggingEvent > {
32- private @ Nullable String dsn ;
33- private @ Nullable String environment ;
34- private @ Nullable Integer maxBreadcrumbs ;
35- private @ Nullable Integer shutdownTimeoutMillis ;
36- private @ Nullable Integer flushTimeoutMillis ;
37- private @ Nullable Integer readTimeoutMillis ;
38- private @ Nullable Double sampleRate ;
39- private @ Nullable Boolean bypassSecurity ;
40- private @ Nullable Boolean debug ;
41- private @ Nullable Boolean attachThreads ;
42- private @ Nullable Boolean attachStacktrace ;
30+ private @ Nullable SentryOptions options ;
4331 private @ Nullable ITransport transport ;
4432
4533 @ Override
4634 public void start () {
47- if (dsn != null ) {
48- Sentry .init (
49- options -> {
50- options .setDsn (dsn );
51- Optional .ofNullable (maxBreadcrumbs ).ifPresent (options ::setMaxBreadcrumbs );
52- Optional .ofNullable (environment ).ifPresent (options ::setEnvironment );
53- Optional .ofNullable (shutdownTimeoutMillis ).ifPresent (options ::setShutdownTimeout );
54- Optional .ofNullable (flushTimeoutMillis ).ifPresent (options ::setFlushTimeoutMillis );
55- Optional .ofNullable (readTimeoutMillis ).ifPresent (options ::setReadTimeoutMillis );
56- Optional .ofNullable (sampleRate ).ifPresent (options ::setSampleRate );
57- Optional .ofNullable (bypassSecurity ).ifPresent (options ::setBypassSecurity );
58- Optional .ofNullable (debug ).ifPresent (options ::setDebug );
59- Optional .ofNullable (attachThreads ).ifPresent (options ::setAttachThreads );
60- Optional .ofNullable (attachStacktrace ).ifPresent (options ::setAttachStacktrace );
61- options .setSentryClientName (BuildConfig .SENTRY_LOGBACK_SDK_NAME );
62- options .setSdkVersion (createSdkVersion (options ));
63- Optional .ofNullable (transport ).ifPresent (options ::setTransport );
64- });
35+ if (options != null && options .getDsn () != null ) {
36+ options .setSentryClientName (BuildConfig .SENTRY_LOGBACK_SDK_NAME );
37+ options .setSdkVersion (createSdkVersion (options ));
38+ Optional .ofNullable (transport ).ifPresent (options ::setTransport );
39+ Sentry .init (options );
6540 }
6641 super .start ();
6742 }
@@ -79,7 +54,8 @@ protected void append(@NotNull ILoggingEvent eventObject) {
7954 */
8055 @ SuppressWarnings ("JdkObsolete" )
8156 final @ NotNull SentryEvent createEvent (@ NotNull ILoggingEvent loggingEvent ) {
82- final SentryEvent event = new SentryEvent (DateUtils .getDateTime (new Date (loggingEvent .getTimeStamp ())));
57+ final SentryEvent event =
58+ new SentryEvent (DateUtils .getDateTime (new Date (loggingEvent .getTimeStamp ())));
8359 final Message message = new Message ();
8460 message .setMessage (loggingEvent .getMessage ());
8561 message .setFormatted (loggingEvent .getFormattedMessage ());
@@ -97,7 +73,8 @@ protected void append(@NotNull ILoggingEvent eventObject) {
9773 event .setExtra ("thread_name" , loggingEvent .getThreadName ());
9874 }
9975
100- final Map <String , String > mdcProperties = CollectionUtils .shallowCopy (loggingEvent .getMDCPropertyMap ());
76+ final Map <String , String > mdcProperties =
77+ CollectionUtils .shallowCopy (loggingEvent .getMDCPropertyMap ());
10178 if (!mdcProperties .isEmpty ()) {
10279 event .getContexts ().put ("MDC" , mdcProperties );
10380 }
@@ -149,48 +126,8 @@ protected void append(@NotNull ILoggingEvent eventObject) {
149126 return sdkVersion ;
150127 }
151128
152- public void setDsn (@ Nullable String dsn ) {
153- this .dsn = dsn ;
154- }
155-
156- public void setEnvironment (@ Nullable String environment ) {
157- this .environment = environment ;
158- }
159-
160- public void setMaxBreadcrumbs (@ Nullable Integer maxBreadcrumbs ) {
161- this .maxBreadcrumbs = maxBreadcrumbs ;
162- }
163-
164- public void setShutdownTimeoutMillis (@ Nullable Integer shutdownTimeoutMillis ) {
165- this .shutdownTimeoutMillis = shutdownTimeoutMillis ;
166- }
167-
168- public void setFlushTimeoutMillis (@ Nullable Integer flushTimeoutMillis ) {
169- this .flushTimeoutMillis = flushTimeoutMillis ;
170- }
171-
172- public void setReadTimeoutMillis (@ Nullable Integer readTimeoutMillis ) {
173- this .readTimeoutMillis = readTimeoutMillis ;
174- }
175-
176- public void setSampleRate (@ Nullable Double sampleRate ) {
177- this .sampleRate = sampleRate ;
178- }
179-
180- public void setBypassSecurity (@ Nullable Boolean bypassSecurity ) {
181- this .bypassSecurity = bypassSecurity ;
182- }
183-
184- public void setDebug (@ Nullable Boolean debug ) {
185- this .debug = debug ;
186- }
187-
188- public void setAttachThreads (@ Nullable Boolean attachThreads ) {
189- this .attachThreads = attachThreads ;
190- }
191-
192- public void setAttachStacktrace (@ Nullable Boolean attachStacktrace ) {
193- this .attachStacktrace = attachStacktrace ;
129+ public void setOptions (SentryOptions options ) {
130+ this .options = options ;
194131 }
195132
196133 @ ApiStatus .Internal
0 commit comments