[lttng-dev] [PATCH lttng-ust stable-2.7] Fix: Ensure the Java JUL messages are correctly formatted

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Thu Feb 4 15:14:57 EST 2016


Merged into lttng-ust stable-2.7 branch, thanks!

Mathieu

----- On Feb 4, 2016, at 3:02 PM, Alexandre Montplaisir alexmonthy at efficios.com wrote:

> Same as 4721f9c, but for the stable-2.7 branch.
> 
> Signed-off-by: Alexandre Montplaisir <alexmonthy at efficios.com>
> ---
> .../java/org/lttng/ust/agent/jul/LTTngLogHandler.java  | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git
> a/liblttng-ust-java-agent/java/org/lttng/ust/agent/jul/LTTngLogHandler.java
> b/liblttng-ust-java-agent/java/org/lttng/ust/agent/jul/LTTngLogHandler.java
> index b844d2f..15c7a8e 100644
> --- a/liblttng-ust-java-agent/java/org/lttng/ust/agent/jul/LTTngLogHandler.java
> +++ b/liblttng-ust-java-agent/java/org/lttng/ust/agent/jul/LTTngLogHandler.java
> @@ -19,11 +19,23 @@ package org.lttng.ust.agent.jul;
> 
> import java.lang.String;
> 
> +import java.util.logging.Formatter;
> import java.util.logging.Handler;
> import java.util.logging.LogRecord;
> 
> class LTTngLogHandler extends Handler {
> 
> +	/**
> +	 * 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 Boolean isRoot;
> 
> 	public LTTngLogHandler(Boolean isRoot) {
> @@ -54,18 +66,20 @@ class LTTngLogHandler extends Handler {
> 
> 	@Override
> 	public void publish(LogRecord record) {
> +		String formattedMessage = FORMATTER.formatMessage(record);
> +
> 		/*
> 		 * 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.
> 		 */
> 		if (this.isRoot) {
> -			tracepointS(record.getMessage(),
> +			tracepointS(formattedMessage,
> 				    record.getLoggerName(), record.getSourceClassName(),
> 				    record.getSourceMethodName(), record.getMillis(),
> 				    record.getLevel().intValue(), record.getThreadID());
> 		} else {
> -			tracepointU(record.getMessage(),
> +			tracepointU(formattedMessage,
> 				    record.getLoggerName(), record.getSourceClassName(),
> 				    record.getSourceMethodName(), record.getMillis(),
> 				    record.getLevel().intValue(), record.getThreadID());
> --
> 2.5.0
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list