Skip to content

Commit 7835ab7

Browse files
committed
added threadId converter, configured its aliases, and improved javadoc
1 parent c428711 commit 7835ab7

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@
2525
import ch.qos.logback.core.pattern.parser.Parser;
2626

2727
/**
28-
* <p>
2928
* A flexible layout configurable with pattern string. The goal of this class is
30-
* to {@link #format format} a {@link ILoggingEvent} and return the results in a
31-
* {#link String}. The format of the result depends on the <em>conversion
29+
* to format a {@link ILoggingEvent} and return the results in a
30+
* {@link String}. The format of the result depends on the <em>conversion
3231
* pattern</em>.
3332
* <p>
34-
* For more information about this layout, please refer to the online manual at
35-
* http://logback.qos.ch/manual/layouts.html#PatternLayout
36-
*
33+
* For more information about this layout, please refer to
34+
* <a href="http://logback.qos.ch/manual/layouts.html#PatternLayout">the online manual</a>.
3735
*/
38-
3936
public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {
4037

4138
public static final Map<String, String> DEFAULT_CONVERTER_MAP = new HashMap<String, String>();
@@ -73,6 +70,10 @@ public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {
7370
DEFAULT_CONVERTER_MAP.put("thread", ThreadConverter.class.getName());
7471
CONVERTER_CLASS_TO_KEY_MAP.put(ThreadConverter.class.getName(), "thread");
7572

73+
DEFAULT_CONVERTER_MAP.put("tid", ThreadIdConverter.class.getName());
74+
DEFAULT_CONVERTER_MAP.put("threadId", ThreadIdConverter.class.getName());
75+
CONVERTER_CLASS_TO_KEY_MAP.put(ThreadIdConverter.class.getName(), "threadId");
76+
7677
DEFAULT_CONVERTER_MAP.put("lo", LoggerConverter.class.getName());
7778
DEFAULT_CONVERTER_MAP.put("logger", LoggerConverter.class.getName());
7879
DEFAULT_CONVERTER_MAP.put("c", LoggerConverter.class.getName());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Logback: the reliable, generic, fast and flexible logging framework.
3+
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4+
*
5+
* This program and the accompanying materials are dual-licensed under
6+
* either the terms of the Eclipse Public License v1.0 as published by
7+
* the Eclipse Foundation
8+
*
9+
* or (per the licensee's choosing)
10+
*
11+
* under the terms of the GNU Lesser General Public License version 2.1
12+
* as published by the Free Software Foundation.
13+
*/
14+
package ch.qos.logback.classic.pattern;
15+
16+
import ch.qos.logback.classic.spi.ILoggingEvent;
17+
18+
/**
19+
* Returns the id of the current thread.
20+
*
21+
* @author Roberto Cella
22+
*/
23+
public class ThreadIdConverter extends ClassicConverter {
24+
25+
public String convert(ILoggingEvent event) {
26+
return String.valueOf(Thread.currentThread().getId());
27+
}
28+
29+
}

0 commit comments

Comments
 (0)