1 /*
2 * Copyright 1999,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package jgroup.util;
18
19 import org.apache.log4j.ULogger;
20 import org.apache.log4j.pattern.LoggingEventPatternConverter;
21 import org.apache.log4j.spi.LoggingEvent;
22
23 /**
24 * Return the events thread (usually the current thread) in a StringBuffer.
25 * This buffer is recycled!
26 *
27 * @author Ceki Gülcü
28 * @author Hein Meling
29 */
30 public class ThreadIdPatternConverter
31 extends LoggingEventPatternConverter
32 {
33
34 /**
35 * Singleton.
36 */
37 private static final ThreadIdPatternConverter INSTANCE =
38 new ThreadIdPatternConverter();
39
40 /**
41 * private constructor
42 */
43 private ThreadIdPatternConverter()
44 {
45 super("tid", "tid");
46 }
47
48 /**
49 * Obtains an instance of ThreadIdPatternConverter.
50 * @param options
51 * @param logger
52 * @return
53 */
54 public static ThreadIdPatternConverter newInstance(
55 final String[] options, final ULogger logger) {
56 return INSTANCE;
57 }
58
59 /* (non-Javadoc)
60 * @see org.apache.log4j.pattern.LoggingEventPatternConverter#format(
61 * org.apache.log4j.spi.LoggingEvent, java.lang.StringBuffer)
62 */
63 @Override
64 public void format(LoggingEvent event, StringBuffer toAppendTo)
65 {
66 toAppendTo.append(Thread.currentThread().getId());
67 }
68
69 } // END ThreadIdPatternConverter