56
56
* </li>
57
57
*
58
58
* <li><code>org.slf4j.simpleLogger.defaultLogLevel</code> - Default log level
59
- * for all instances of SimpleLogger. Must be one of ( "trace", "debug", "info",
60
- * "warn", "error" or "off") . If not specified, defaults to "info".</li>
59
+ * for all instances of SimpleLogger. Must be one of "trace", "debug", "info",
60
+ * "warn", "error" or "off". If not specified, defaults to "info".</li>
61
61
*
62
- * <li><code>org.slf4j.simpleLogger.log.<em>a.b.c </em></code> - Logging detail
63
- * level for a SimpleLogger instance named "a.b.c ". Right-side value must be one
62
+ * <li><code>org.slf4j.simpleLogger.log.<em>com.foo.bar </em></code> - Logging detail
63
+ * level for a SimpleLogger instance named "com.foo.bar ". Right-side value must be one
64
64
* of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger
65
65
* named "a.b.c" is initialized, its level is assigned from this property. If
66
66
* unspecified, the level of nearest parent logger will be used, and if none is
67
67
* set, then the value specified by
68
68
* <code>org.slf4j.simpleLogger.defaultLogLevel</code> will be used.</li>
69
69
*
70
- * <li><code>org.slf4j.simpleLogger.showDateTime</code> - Set to
71
- * <code>true</code> if you want the current date and time to be included in
72
- * output messages . Default is <code>false</code></li>
70
+ * <li><code>org.slf4j.simpleLogger.showDateTime</code> - If you would like the
71
+ * current date and time to be included in output messages, then set it to
72
+ * <code>true</code> . Default is <code>false</code></li>
73
73
*
74
74
* <li><code>org.slf4j.simpleLogger.dateTimeFormat</code> - The date and time
75
75
* format to be used in the output messages. The pattern describing the date and
78
78
* <code>SimpleDateFormat</code></a>. If the format is not specified or is
79
79
* invalid, the number of milliseconds since start up will be output.</li>
80
80
*
81
- * <li><code>org.slf4j.simpleLogger.showThreadName</code> -Set to
82
- * <code>true</code> if you want to output the current thread name . Defaults to
81
+ * <li><code>org.slf4j.simpleLogger.showThreadName</code> - If you want to output
82
+ * the current thread name, then set it to <code>true</code> . Defaults to
83
83
* <code>true</code>.</li>
84
84
*
85
- * <li><code>org.slf4j.simpleLogger.showLogName</code> - Set to
86
- * <code>true</code> if you want the Logger instance name to be included in
87
- * output messages. Defaults to <code>true</code>.</li>
85
+ * <li>(since version 1.7.33 and 2.0.0-alpha6) <code>org.slf4j.simpleLogger.showThreadId</code> -
86
+ * If you would like to output the current thread name, then set to
87
+ * <code>true</code>. Defaults to <code>false</code>.</li>
88
+ *
89
+ * <li><code>org.slf4j.simpleLogger.showLogName</code> - If you would like
90
+ * the Logger instance name to be included in output messages, then set it to
91
+ * <code>true</code>. Defaults to <code>true</code>.</li>
88
92
*
89
93
* <li><code>org.slf4j.simpleLogger.showShortLogName</code> - Set to
90
94
* <code>true</code> if you want the last component of the name to be included
142
146
*/
143
147
public class SimpleLogger extends MarkerIgnoringBase {
144
148
145
- private static final long serialVersionUID = -632788891211436180L ;
149
+
150
+ private static final long serialVersionUID = -632788891211436180L ;
146
151
147
152
private static long START_TIME = System .currentTimeMillis ();
148
153
@@ -151,6 +156,9 @@ public class SimpleLogger extends MarkerIgnoringBase {
151
156
protected static final int LOG_LEVEL_INFO = LocationAwareLogger .INFO_INT ;
152
157
protected static final int LOG_LEVEL_WARN = LocationAwareLogger .WARN_INT ;
153
158
protected static final int LOG_LEVEL_ERROR = LocationAwareLogger .ERROR_INT ;
159
+
160
+ private static final String TID_PREFIX = "tid=" ;
161
+
154
162
// The OFF level can only be used in configuration files to disable logging.
155
163
// It has
156
164
// no printing method associated with it in o.s.Logger interface.
@@ -200,6 +208,8 @@ static void init() {
200
208
201
209
public static final String SHOW_THREAD_NAME_KEY = SimpleLogger .SYSTEM_PREFIX + "showThreadName" ;
202
210
211
+ public static final String SHOW_THREAD_ID_KEY = SimpleLogger .SYSTEM_PREFIX + "showThreadId" ;
212
+
203
213
public static final String DATE_TIME_FORMAT_KEY = SimpleLogger .SYSTEM_PREFIX + "dateTimeFormat" ;
204
214
205
215
public static final String SHOW_DATE_TIME_KEY = SimpleLogger .SYSTEM_PREFIX + "showDateTime" ;
@@ -269,6 +279,12 @@ private void log(int level, String message, Throwable t) {
269
279
buf .append ("] " );
270
280
}
271
281
282
+ if (CONFIG_PARAMS .showThreadId ) {
283
+ buf .append (TID_PREFIX );
284
+ buf .append (Thread .currentThread ().getId ());
285
+ buf .append (' ' );
286
+ }
287
+
272
288
if (CONFIG_PARAMS .levelInBrackets )
273
289
buf .append ('[' );
274
290
@@ -326,7 +342,6 @@ void write(StringBuilder buf, Throwable t) {
326
342
writeThrowable (t , targetStream );
327
343
targetStream .flush ();
328
344
}
329
-
330
345
}
331
346
332
347
protected void writeThrowable (Throwable t , PrintStream targetStream ) {
0 commit comments