Skip to content

Commit 0d9c91a

Browse files
committed
Making thread name in logs the default
1 parent 661f187 commit 0d9c91a

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/main/java/org/datadog/jmxfetch/AppConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class AppConfig {
101101
description = "Logs the thread name with each message",
102102
required = false)
103103
@Builder.Default
104-
private boolean logThreadName = false;
104+
private boolean logThreadName = true;
105105

106106
@Parameter(
107107
names = {"--conf_directory", "-D"},

src/main/java/org/datadog/jmxfetch/util/CustomLogger.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ private static SimpleFormatter getFormatter(
139139

140140
// log format
141141
return new SimpleFormatter() {
142-
private final String formatLayout =
143-
logThreadName ? JDK14_WITH_THREADS_LAYOUT : JDK14_LAYOUT;
144142

145143
private String simpleClassName(String str) {
146144
int start = str.lastIndexOf('.');
@@ -170,14 +168,8 @@ public synchronized String format(LogRecord lr) {
170168
Throwable throwable = new Throwable();
171169
StackTraceElement logEmissionFrame = throwable.getStackTrace()[6];
172170

173-
final String logFormat;
174171
if (logThreadName) {
175-
logFormat = JDK14_WITH_THREADS_LAYOUT_FILE_LINE;
176-
} else {
177-
logFormat = JDK14_LAYOUT_FILE_LINE;
178-
}
179-
if (logThreadName) {
180-
return String.format(logFormat,
172+
return String.format(JDK14_WITH_THREADS_LAYOUT_FILE_LINE,
181173
dateFormatter.format(new Date()),
182174
LogLevel.fromJulLevel(lr.getLevel()).toString(),
183175
Thread.currentThread().getName(),
@@ -187,7 +179,8 @@ public synchronized String format(LogRecord lr) {
187179
exception
188180
);
189181
}
190-
return String.format(logFormat,
182+
183+
return String.format(JDK14_LAYOUT_FILE_LINE,
191184
dateFormatter.format(new Date()),
192185
LogLevel.fromJulLevel(lr.getLevel()).toString(),
193186
logEmissionFrame.getFileName(),
@@ -198,7 +191,7 @@ public synchronized String format(LogRecord lr) {
198191
}
199192

200193
if (logThreadName) {
201-
return String.format(formatLayout,
194+
return String.format(JDK14_WITH_THREADS_LAYOUT,
202195
dateFormatter.format(new Date()),
203196
LogLevel.fromJulLevel(lr.getLevel()).toString(),
204197
Thread.currentThread().getName(),
@@ -207,7 +200,7 @@ public synchronized String format(LogRecord lr) {
207200
exception
208201
);
209202
}
210-
return String.format(formatLayout,
203+
return String.format(JDK14_LAYOUT,
211204
dateFormatter.format(new Date()),
212205
LogLevel.fromJulLevel(lr.getLevel()).toString(),
213206
simpleClassName(lr.getSourceClassName()),

0 commit comments

Comments
 (0)