Fix: Ensure the Java JUL messages are correctly formatted
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · ----- On Feb 4, 2016, at 12:32 AM, Alexandre Montplaisir…
It is possible for log records to contain messages that need some formatting, for example if the string contains localized elements or if the
log(Level, String, Object[])method is used.In these cases, we need to make sure to format the string and not pass the "raw" string to the tracepoint.
This only applies to the JUL API. log4j 1.2.x did not handle such formatting, although log4j 2.x does.
Hi Alexandre,
The fix applies fine to master (merged). Can you also provide a fix for stable-2.7 ? The cherry-pick is not straightforward.
Thanks!
Mathieu
Quoted 67 lines
Signed-off-by Alexandre Montplaisir <[email protected]>---
.../org/lttng/ust/agent/jul/LttngLogHandler.java | 16 +++++++++++++++-1 file changed, 15 insertions(+), 1 deletion(-)diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java index d8e0cb8..39e08a8 100644
---
a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java
+++
b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java(quoted diff) +12
-0@@ -20,6 +20,7 @@ package org.lttng.ust.agent.jul; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; +import java.util.logging.Formatter; import java.util.logging.Handler; import java.util.logging.LogRecord;@@ -43,6 +44,17 @@ public class LttngLogHandler extends Handler implements ILttngHandler { private static final String SHARED_OBJECT_NAME = "lttng-ust-jul-jni"; + /** + * Dummy Formatter object, so we can use its + * {@link Formatter#formatMessage(LogRecord)} method. + */ + private static final Formatter FORMATTER = new Formatter() { + @Override + public String format(LogRecord record) { + throw new UnsupportedOperationException(); + } + }; + private final ILttngAgent<LttngLogHandler> agent;/** Number of events logged (really sent through JNI) by this handler */(quoted diff) +3
-1@@ -103,13 +115,15 @@ public class LttngLogHandler extends Handler implements ILttngHandler { return; } + String formattedMessage = FORMATTER.formatMessage(record); + eventCount.incrementAndGet(); /* * Specific tracepoint designed for JUL events. The source class of the * caller is used for the event name, the raw message is taken, the * loglevel of the record and the thread ID. */ - tracepoint(record.getMessage(), + tracepoint(formattedMessage, record.getLoggerName(), record.getSourceClassName(),
record.getSourceMethodName(),
--
2.5.0_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Mathieu Desnoyers
Quoted 7 lines · ----- On Feb 4, 2016, at 12:32 AM, Alexandre Montplaisir…
It is possible for log records to contain messages that need some formatting, for example if the string contains localized elements or if the
log(Level, String, Object[])method is used.In these cases, we need to make sure to format the string and not pass the "raw" string to the tracepoint.
Quoted 6 lines
Quoted 2 lines
This only applies to the JUL API. log4j 1.2.x did not handle such formatting, although log4j 2.x does.
Hi Alexandre,
The fix applies fine to master (merged). Can you also provide a fix for stable-2.7 ? The cherry-pick is not straightforward.
Sure, I have just tested an equivalent fix for 2.7, I will send it shortly.
Alexandre
Quoted 71 lines
Thanks!
Mathieu
Quoted 66 lines
Signed-off-by Alexandre Montplaisir <[email protected]>---
.../org/lttng/ust/agent/jul/LttngLogHandler.java | 16 +++++++++++++++-1 file changed, 15 insertions(+), 1 deletion(-)diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java index d8e0cb8..39e08a8 100644
---
a/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java
+++
b/liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngLogHandler.java(quoted diff) +12
-0@@ -20,6 +20,7 @@ package org.lttng.ust.agent.jul; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; +import java.util.logging.Formatter; import java.util.logging.Handler; import java.util.logging.LogRecord;@@ -43,6 +44,17 @@ public class LttngLogHandler extends Handler implements ILttngHandler { private static final String SHARED_OBJECT_NAME = "lttng-ust-jul-jni"; + /** + * Dummy Formatter object, so we can use its + * {@link Formatter#formatMessage(LogRecord)} method. + */ + private static final Formatter FORMATTER = new Formatter() { + @Override + public String format(LogRecord record) { + throw new UnsupportedOperationException(); + } + }; + private final ILttngAgent<LttngLogHandler> agent;/** Number of events logged (really sent through JNI) by this handler */(quoted diff) +3
-1@@ -103,13 +115,15 @@ public class LttngLogHandler extends Handler implements ILttngHandler { return; } + String formattedMessage = FORMATTER.formatMessage(record); + eventCount.incrementAndGet(); /* * Specific tracepoint designed for JUL events. The source class of the * caller is used for the event name, the raw message is taken, the * loglevel of the record and the thread ID. */ - tracepoint(record.getMessage(), + tracepoint(formattedMessage, record.getLoggerName(), record.getSourceClassName(),
record.getSourceMethodName(),
--
2.5.0_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev