diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java b/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java index ca54986553..32c6f7e7aa 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java @@ -25,17 +25,14 @@ import ch.qos.logback.core.pattern.parser.Parser; /** - *

* A flexible layout configurable with pattern string. The goal of this class is - * to {@link #format format} a {@link ILoggingEvent} and return the results in a - * {#link String}. The format of the result depends on the conversion + * to format a {@link ILoggingEvent} and return the results in a + * {@link String}. The format of the result depends on the conversion * pattern. *

- * For more information about this layout, please refer to the online manual at - * http://logback.qos.ch/manual/layouts.html#PatternLayout - * + * For more information about this layout, please refer to + * the online manual. */ - public class PatternLayout extends PatternLayoutBase { public static final Map DEFAULT_CONVERTER_MAP = new HashMap(); @@ -73,6 +70,10 @@ public class PatternLayout extends PatternLayoutBase { DEFAULT_CONVERTER_MAP.put("thread", ThreadConverter.class.getName()); CONVERTER_CLASS_TO_KEY_MAP.put(ThreadConverter.class.getName(), "thread"); + DEFAULT_CONVERTER_MAP.put("tid", ThreadIdConverter.class.getName()); + DEFAULT_CONVERTER_MAP.put("threadId", ThreadIdConverter.class.getName()); + CONVERTER_CLASS_TO_KEY_MAP.put(ThreadIdConverter.class.getName(), "threadId"); + DEFAULT_CONVERTER_MAP.put("lo", LoggerConverter.class.getName()); DEFAULT_CONVERTER_MAP.put("logger", LoggerConverter.class.getName()); DEFAULT_CONVERTER_MAP.put("c", LoggerConverter.class.getName()); diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThreadIdConverter.java b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThreadIdConverter.java new file mode 100644 index 0000000000..54b6372b5b --- /dev/null +++ b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThreadIdConverter.java @@ -0,0 +1,29 @@ +/** + * Logback: the reliable, generic, fast and flexible logging framework. + * Copyright (C) 1999-2015, QOS.ch. All rights reserved. + * + * This program and the accompanying materials are dual-licensed under + * either the terms of the Eclipse Public License v1.0 as published by + * the Eclipse Foundation + * + * or (per the licensee's choosing) + * + * under the terms of the GNU Lesser General Public License version 2.1 + * as published by the Free Software Foundation. + */ +package ch.qos.logback.classic.pattern; + +import ch.qos.logback.classic.spi.ILoggingEvent; + +/** + * Returns the id of the current thread. + * + * @author Roberto Cella + */ +public class ThreadIdConverter extends ClassicConverter { + + public String convert(ILoggingEvent event) { + return String.valueOf(Thread.currentThread().getId()); + } + +}