Skip to content

Commit

Permalink
Making thread name in logs the default
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman committed Jun 5, 2024
1 parent 661f187 commit 0d9c91a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class AppConfig {
description = "Logs the thread name with each message",
required = false)
@Builder.Default
private boolean logThreadName = false;
private boolean logThreadName = true;

@Parameter(
names = {"--conf_directory", "-D"},
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/org/datadog/jmxfetch/util/CustomLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ private static SimpleFormatter getFormatter(

// log format
return new SimpleFormatter() {
private final String formatLayout =
logThreadName ? JDK14_WITH_THREADS_LAYOUT : JDK14_LAYOUT;

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

final String logFormat;
if (logThreadName) {
logFormat = JDK14_WITH_THREADS_LAYOUT_FILE_LINE;
} else {
logFormat = JDK14_LAYOUT_FILE_LINE;
}
if (logThreadName) {
return String.format(logFormat,
return String.format(JDK14_WITH_THREADS_LAYOUT_FILE_LINE,
dateFormatter.format(new Date()),
LogLevel.fromJulLevel(lr.getLevel()).toString(),
Thread.currentThread().getName(),
Expand All @@ -187,7 +179,8 @@ public synchronized String format(LogRecord lr) {
exception
);
}
return String.format(logFormat,

return String.format(JDK14_LAYOUT_FILE_LINE,
dateFormatter.format(new Date()),
LogLevel.fromJulLevel(lr.getLevel()).toString(),
logEmissionFrame.getFileName(),
Expand All @@ -198,7 +191,7 @@ public synchronized String format(LogRecord lr) {
}

if (logThreadName) {
return String.format(formatLayout,
return String.format(JDK14_WITH_THREADS_LAYOUT,
dateFormatter.format(new Date()),
LogLevel.fromJulLevel(lr.getLevel()).toString(),
Thread.currentThread().getName(),
Expand All @@ -207,7 +200,7 @@ public synchronized String format(LogRecord lr) {
exception
);
}
return String.format(formatLayout,
return String.format(JDK14_LAYOUT,
dateFormatter.format(new Date()),
LogLevel.fromJulLevel(lr.getLevel()).toString(),
simpleClassName(lr.getSourceClassName()),
Expand Down

0 comments on commit 0d9c91a

Please sign in to comment.