Skip to content

Commit 4fa3eaf

Browse files
committed
Format code
1 parent 8fe41f8 commit 4fa3eaf

File tree

2 files changed

+95
-104
lines changed

2 files changed

+95
-104
lines changed

sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java

Lines changed: 81 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
import io.sentry.protocol.SdkVersion;
2727
import io.sentry.util.CollectionUtils;
2828
import io.sentry.util.ContextTagsUtil;
29-
3029
import java.util.Arrays;
3130
import java.util.Collections;
3231
import java.util.List;
3332
import java.util.Map;
3433
import java.util.Objects;
3534
import java.util.Optional;
3635
import java.util.stream.Collectors;
37-
3836
import org.apache.logging.log4j.Level;
3937
import org.apache.logging.log4j.core.Filter;
4038
import org.apache.logging.log4j.core.LogEvent;
@@ -47,9 +45,7 @@
4745
import org.jetbrains.annotations.NotNull;
4846
import org.jetbrains.annotations.Nullable;
4947

50-
/**
51-
* Appender for Log4j2 in charge of sending the logged events to a Sentry server.
52-
*/
48+
/** Appender for Log4j2 in charge of sending the logged events to a Sentry server. */
5349
@Plugin(name = "Sentry", category = "Core", elementType = "appender", printObject = true)
5450
@Open
5551
public class SentryAppender extends AbstractAppender {
@@ -66,49 +62,49 @@ public class SentryAppender extends AbstractAppender {
6662

6763
static {
6864
SentryIntegrationPackageStorage.getInstance()
69-
.addPackage("maven:io.sentry:sentry-log4j2", BuildConfig.VERSION_NAME);
65+
.addPackage("maven:io.sentry:sentry-log4j2", BuildConfig.VERSION_NAME);
7066
}
7167

7268
/**
7369
* @deprecated This constructor is deprecated. Please use {@link #SentryAppender(String, Filter,
74-
* String, Level, Level, Level, Boolean, ITransportFactory, IScopes, String[])} instead.
70+
* String, Level, Level, Level, Boolean, ITransportFactory, IScopes, String[])} instead.
7571
*/
7672
@Deprecated
7773
@SuppressWarnings("InlineMeSuggester")
7874
public SentryAppender(
79-
final @NotNull String name,
80-
final @Nullable Filter filter,
81-
final @Nullable String dsn,
82-
final @Nullable Level minimumBreadcrumbLevel,
83-
final @Nullable Level minimumEventLevel,
84-
final @Nullable Boolean debug,
85-
final @Nullable ITransportFactory transportFactory,
86-
final @NotNull IScopes scopes,
87-
final @Nullable String[] contextTags) {
75+
final @NotNull String name,
76+
final @Nullable Filter filter,
77+
final @Nullable String dsn,
78+
final @Nullable Level minimumBreadcrumbLevel,
79+
final @Nullable Level minimumEventLevel,
80+
final @Nullable Boolean debug,
81+
final @Nullable ITransportFactory transportFactory,
82+
final @NotNull IScopes scopes,
83+
final @Nullable String[] contextTags) {
8884
this(
89-
name,
90-
filter,
91-
dsn,
92-
minimumBreadcrumbLevel,
93-
minimumEventLevel,
94-
null,
95-
debug,
96-
transportFactory,
97-
scopes,
98-
contextTags);
85+
name,
86+
filter,
87+
dsn,
88+
minimumBreadcrumbLevel,
89+
minimumEventLevel,
90+
null,
91+
debug,
92+
transportFactory,
93+
scopes,
94+
contextTags);
9995
}
10096

10197
public SentryAppender(
102-
final @NotNull String name,
103-
final @Nullable Filter filter,
104-
final @Nullable String dsn,
105-
final @Nullable Level minimumBreadcrumbLevel,
106-
final @Nullable Level minimumEventLevel,
107-
final @Nullable Level minimumLevel,
108-
final @Nullable Boolean debug,
109-
final @Nullable ITransportFactory transportFactory,
110-
final @NotNull IScopes scopes,
111-
final @Nullable String[] contextTags) {
98+
final @NotNull String name,
99+
final @Nullable Filter filter,
100+
final @Nullable String dsn,
101+
final @Nullable Level minimumBreadcrumbLevel,
102+
final @Nullable Level minimumEventLevel,
103+
final @Nullable Level minimumLevel,
104+
final @Nullable Boolean debug,
105+
final @Nullable ITransportFactory transportFactory,
106+
final @NotNull IScopes scopes,
107+
final @Nullable String[] contextTags) {
112108
super(name, filter, null, true, null);
113109
this.dsn = dsn;
114110
if (minimumBreadcrumbLevel != null) {
@@ -129,64 +125,64 @@ public SentryAppender(
129125
/**
130126
* Create a Sentry Appender.
131127
*
132-
* @param name The name of the Appender.
128+
* @param name The name of the Appender.
133129
* @param minimumBreadcrumbLevel The min. level of the breadcrumb.
134-
* @param minimumEventLevel The min. level of the event.
135-
* @param minimumLevel The min. level of the log event.
136-
* @param dsn the Sentry DSN.
137-
* @param debug if Sentry debug mode should be on
138-
* @param filter The filter, if any, to use.
130+
* @param minimumEventLevel The min. level of the event.
131+
* @param minimumLevel The min. level of the log event.
132+
* @param dsn the Sentry DSN.
133+
* @param debug if Sentry debug mode should be on
134+
* @param filter The filter, if any, to use.
139135
* @return The SentryAppender.
140136
*/
141137
@PluginFactory
142138
public static @Nullable SentryAppender createAppender(
143-
@Nullable @PluginAttribute("name") final String name,
144-
@Nullable @PluginAttribute("minimumBreadcrumbLevel") final Level minimumBreadcrumbLevel,
145-
@Nullable @PluginAttribute("minimumEventLevel") final Level minimumEventLevel,
146-
@Nullable @PluginAttribute("minimumLevel") final Level minimumLevel,
147-
@Nullable @PluginAttribute("dsn") final String dsn,
148-
@Nullable @PluginAttribute("debug") final Boolean debug,
149-
@Nullable @PluginElement("filter") final Filter filter,
150-
@Nullable @PluginAttribute("contextTags") final String contextTags) {
139+
@Nullable @PluginAttribute("name") final String name,
140+
@Nullable @PluginAttribute("minimumBreadcrumbLevel") final Level minimumBreadcrumbLevel,
141+
@Nullable @PluginAttribute("minimumEventLevel") final Level minimumEventLevel,
142+
@Nullable @PluginAttribute("minimumLevel") final Level minimumLevel,
143+
@Nullable @PluginAttribute("dsn") final String dsn,
144+
@Nullable @PluginAttribute("debug") final Boolean debug,
145+
@Nullable @PluginElement("filter") final Filter filter,
146+
@Nullable @PluginAttribute("contextTags") final String contextTags) {
151147

152148
if (name == null) {
153149
LOGGER.error("No name provided for SentryAppender");
154150
return null;
155151
}
156152
return new SentryAppender(
157-
name,
158-
filter,
159-
dsn,
160-
minimumBreadcrumbLevel,
161-
minimumEventLevel,
162-
minimumLevel,
163-
debug,
164-
null,
165-
ScopesAdapter.getInstance(),
166-
contextTags != null ? contextTags.split(",") : null);
153+
name,
154+
filter,
155+
dsn,
156+
minimumBreadcrumbLevel,
157+
minimumEventLevel,
158+
minimumLevel,
159+
debug,
160+
null,
161+
ScopesAdapter.getInstance(),
162+
contextTags != null ? contextTags.split(",") : null);
167163
}
168164

169165
@Override
170166
public void start() {
171167
try {
172168
Sentry.init(
173-
options -> {
174-
options.setEnableExternalConfiguration(true);
175-
options.setInitPriority(InitPriority.LOWEST);
176-
options.setDsn(dsn);
177-
if (debug != null) {
178-
options.setDebug(debug);
179-
}
180-
options.setSentryClientName(
181-
BuildConfig.SENTRY_LOG4J2_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
182-
options.setSdkVersion(createSdkVersion(options));
183-
if (contextTags != null) {
184-
for (final String contextTag : contextTags) {
185-
options.addContextTag(contextTag);
169+
options -> {
170+
options.setEnableExternalConfiguration(true);
171+
options.setInitPriority(InitPriority.LOWEST);
172+
options.setDsn(dsn);
173+
if (debug != null) {
174+
options.setDebug(debug);
175+
}
176+
options.setSentryClientName(
177+
BuildConfig.SENTRY_LOG4J2_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
178+
options.setSdkVersion(createSdkVersion(options));
179+
if (contextTags != null) {
180+
for (final String contextTag : contextTags) {
181+
options.addContextTag(contextTag);
182+
}
186183
}
187-
}
188-
Optional.ofNullable(transportFactory).ifPresent(options::setTransportFactory);
189-
});
184+
Optional.ofNullable(transportFactory).ifPresent(options::setTransportFactory);
185+
});
190186
} catch (IllegalArgumentException e) {
191187
LOGGER.warn("Failed to init Sentry during appender initialization: " + e.getMessage());
192188
}
@@ -197,7 +193,7 @@ public void start() {
197193
@Override
198194
public void append(final @NotNull LogEvent eventObject) {
199195
if (scopes.getOptions().getLogs().isEnabled()
200-
&& eventObject.getLevel().isMoreSpecificThan(minimumLevel)) {
196+
&& eventObject.getLevel().isMoreSpecificThan(minimumLevel)) {
201197
captureLog(eventObject);
202198
}
203199
if (eventObject.getLevel().isMoreSpecificThan(minimumEventLevel)) {
@@ -232,7 +228,7 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
232228

233229
if (nonFormattedMessage != null && !formattedMessage.equals(nonFormattedMessage)) {
234230
attributes.add(
235-
SentryAttribute.stringAttribute("sentry.message.template", nonFormattedMessage));
231+
SentryAttribute.stringAttribute("sentry.message.template", nonFormattedMessage));
236232
}
237233

238234
final Map<String, String> contextData = loggingEvent.getContextData().toMap();
@@ -269,8 +265,8 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
269265
final Mechanism mechanism = new Mechanism();
270266
mechanism.setType(MECHANISM_TYPE);
271267
final Throwable mechanismException =
272-
new ExceptionMechanismException(
273-
mechanism, throwableInformation.getThrowable(), Thread.currentThread());
268+
new ExceptionMechanismException(
269+
mechanism, throwableInformation.getThrowable(), Thread.currentThread());
274270
event.setThrowable(mechanismException);
275271
}
276272

@@ -283,8 +279,8 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
283279
}
284280

285281
final Map<String, String> contextData =
286-
CollectionUtils.filterMapEntries(
287-
loggingEvent.getContextData().toMap(), entry -> entry.getValue() != null);
282+
CollectionUtils.filterMapEntries(
283+
loggingEvent.getContextData().toMap(), entry -> entry.getValue() != null);
288284
if (!contextData.isEmpty()) {
289285
// get tags from ScopesAdapter options to allow getting the correct tags if Sentry has been
290286
// initialized somewhere else
@@ -304,9 +300,9 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
304300
private @NotNull List<String> toParams(final @Nullable Object[] arguments) {
305301
if (arguments != null) {
306302
return Arrays.stream(arguments)
307-
.filter(Objects::nonNull)
308-
.map(Object::toString)
309-
.collect(Collectors.toList());
303+
.filter(Objects::nonNull)
304+
.map(Object::toString)
305+
.collect(Collectors.toList());
310306
} else {
311307
return Collections.emptyList();
312308
}

sentry/src/main/java/io/sentry/util/ContextTagsUtil.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,29 @@
33
import io.sentry.SentryAttribute;
44
import io.sentry.SentryAttributes;
55
import io.sentry.SentryEvent;
6-
76
import java.util.List;
87
import java.util.Map;
9-
10-
import org.jetbrains.annotations.NotNull;
118
import org.jetbrains.annotations.ApiStatus;
9+
import org.jetbrains.annotations.NotNull;
1210

13-
/**
14-
* Utility class for applying context tags (e.g. MDC) to Sentry events and log attributes.
15-
*/
11+
/** Utility class for applying context tags (e.g. MDC) to Sentry events and log attributes. */
1612
@ApiStatus.Internal
1713
public final class ContextTagsUtil {
1814

1915
/**
2016
* Applies context tags from a properties map to a Sentry event as tags. Context tags that are
2117
* found in the properties map are set as event tags and removed from the properties map.
2218
*
23-
* @param event the Sentry event to add tags to
19+
* @param event the Sentry event to add tags to
2420
* @param contextTags the list of context tag names to look for
25-
* @param properties the properties map (e.g. MDC) - this map will be modified by removing applied context tags
21+
* @param properties the properties map (e.g. MDC) - this map will be modified by removing applied
22+
* context tags
2623
*/
2724
@ApiStatus.Internal
2825
public static void applyContextTagsToEvent(
29-
final @NotNull SentryEvent event,
30-
final @NotNull List<String> contextTags,
31-
final @NotNull Map<String, String> properties) {
26+
final @NotNull SentryEvent event,
27+
final @NotNull List<String> contextTags,
28+
final @NotNull Map<String, String> properties) {
3229
if (!contextTags.isEmpty() && !properties.isEmpty()) {
3330
for (final String contextTag : contextTags) {
3431
if (properties.containsKey(contextTag)) {
@@ -40,20 +37,18 @@ public static void applyContextTagsToEvent(
4037
}
4138

4239
/**
43-
* Applies context tags from a properties map to SentryAttributes for logs.
44-
* Properties with null values are filtered out.
40+
* Applies context tags from a properties map to SentryAttributes for logs. Properties with null
41+
* values are filtered out.
4542
*
46-
* @param attributes the SentryAttributes to add context tags to
47-
* @param properties the properties map (e.g. MDC)
43+
* @param attributes the SentryAttributes to add context tags to
44+
* @param properties the properties map (e.g. MDC)
4845
*/
4946
@ApiStatus.Internal
5047
public static void applyContextTagsToLogAttributes(
51-
final @NotNull SentryAttributes attributes,
52-
final @NotNull Map<String, String> properties) {
48+
final @NotNull SentryAttributes attributes, final @NotNull Map<String, String> properties) {
5349
for (final Map.Entry<String, String> entry : properties.entrySet()) {
5450
if (entry.getValue() != null) {
55-
attributes.add(
56-
SentryAttribute.stringAttribute(entry.getKey(), entry.getValue()));
51+
attributes.add(SentryAttribute.stringAttribute(entry.getKey(), entry.getValue()));
5752
}
5853
}
5954
}

0 commit comments

Comments
 (0)