Skip to content

Commit

Permalink
Set JUL loggerName (#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauhiz authored Dec 15, 2023
1 parent acfd3f3 commit 8fc4b58
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion brave/src/main/java/brave/internal/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package brave.internal;

import brave.Clock;
import brave.Tracer;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
Expand Down Expand Up @@ -81,7 +83,8 @@ public static Platform get() {

// Use nested class to ensure logger isn't initialized unless it is accessed once.
private static final class LoggerHolder {
static final Logger LOG = Logger.getLogger(brave.Tracer.class.getName());
static final String LOGGER_NAME = Tracer.class.getName();
static final Logger LOG = Logger.getLogger(LOGGER_NAME);
}

/** Like {@link Logger#log(Level, String) */
Expand All @@ -96,6 +99,7 @@ public void log(String msg, Object param1, @Nullable Throwable thrown) {
Logger logger = LoggerHolder.LOG;
if (!logger.isLoggable(Level.FINE)) return; // fine level to not fill logs
LogRecord lr = new LogRecord(Level.FINE, msg);
lr.setLoggerName(LoggerHolder.LOGGER_NAME);
Object[] params = {param1};
lr.setParameters(params);
if (thrown != null) lr.setThrown(thrown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public final class JmsTracing {

// Use nested class to ensure logger isn't initialized unless it is accessed once.
private static final class LoggerHolder {
static final Logger LOG = Logger.getLogger(JmsTracing.class.getName());
static final String LOGGER_NAME = JmsTracing.class.getName();
static final Logger LOG = Logger.getLogger(LOGGER_NAME);
}

// Use nested class to ensure we only check once per classloader
Expand Down Expand Up @@ -307,6 +308,7 @@ static void log(Throwable thrown, String msg, Object zero, @Nullable Object one)
Logger logger = LoggerHolder.LOG;
if (!logger.isLoggable(Level.FINE)) return; // fine level to not fill logs
LogRecord lr = new LogRecord(Level.FINE, msg);
lr.setLoggerName(LoggerHolder.LOGGER_NAME);
Object[] params = one != null ? new Object[] {zero, one} : new Object[] {zero};
lr.setParameters(params);
lr.setThrown(thrown);
Expand Down
4 changes: 3 additions & 1 deletion instrumentation/jms/src/main/java/brave/jms/JmsTracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public final class JmsTracing {

// Use nested class to ensure logger isn't initialized unless it is accessed once.
private static final class LoggerHolder {
static final Logger LOG = Logger.getLogger(JmsTracing.class.getName());
static final String LOGGER_NAME = JmsTracing.class.getName();
static final Logger LOG = Logger.getLogger(LOGGER_NAME);
}

// Use nested class to ensure we only check once per classloader
Expand Down Expand Up @@ -308,6 +309,7 @@ static void log(Throwable thrown, String msg, Object zero, @Nullable Object one)
Logger logger = LoggerHolder.LOG;
if (!logger.isLoggable(Level.FINE)) return; // fine level to not fill logs
LogRecord lr = new LogRecord(Level.FINE, msg);
lr.setLoggerName(LoggerHolder.LOGGER_NAME);
Object[] params = one != null ? new Object[] {zero, one} : new Object[] {zero};
lr.setParameters(params);
lr.setThrown(thrown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public final class KafkaTracing {
};
// Use nested class to ensure logger isn't initialized unless it is accessed once.
private static final class LoggerHolder {
static final Logger LOG = Logger.getLogger(KafkaTracing.class.getName());
static final String LOGGER_NAME = KafkaTracing.class.getName();
static final Logger LOG = Logger.getLogger(LOGGER_NAME);
}

public static KafkaTracing create(Tracing tracing) {
Expand Down Expand Up @@ -278,6 +279,7 @@ static void log(Throwable thrown, String msg, Object zero, @Nullable Object one)
Logger logger = LoggerHolder.LOG;
if (!logger.isLoggable(Level.FINE)) return; // fine level to not fill logs
LogRecord lr = new LogRecord(Level.FINE, msg);
lr.setLoggerName(LoggerHolder.LOGGER_NAME);
Object[] params = one != null ? new Object[] {zero, one} : new Object[] {zero};
lr.setParameters(params);
lr.setThrown(thrown);
Expand Down

0 comments on commit 8fc4b58

Please sign in to comment.