Skip to content

Commit

Permalink
added threadId converter, configured its aliases, and improved javadoc
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Cella <[email protected]>
  • Loading branch information
rob93c committed Oct 9, 2023
1 parent c428711 commit 7d04b1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
import ch.qos.logback.core.pattern.parser.Parser;

/**
* <p>
* 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 <em>conversion
* to format a {@link ILoggingEvent} and return the results in a
* {@link String}. The format of the result depends on the <em>conversion
* pattern</em>.
* <p>
* 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
* <a href="http://logback.qos.ch/manual/layouts.html#PatternLayout">the online manual</a>.
*/

public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {

public static final Map<String, String> DEFAULT_CONVERTER_MAP = new HashMap<String, String>();
Expand Down Expand Up @@ -73,6 +70,10 @@ public class PatternLayout extends PatternLayoutBase<ILoggingEvent> {
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit 7d04b1b

Please sign in to comment.