I\'ll try to make a brief description of my Selenium framework so that I can explain my problem.
I use Selenium 2 (current version 2.3.1) + test
If you want thread ids, rather than thread names, and are using an asynchronous appender, Jerico Sandhorn's ThreadIdConverter will not work as expected, because it gets run on a different thread. In that case you can drop in this class.
public class ThreadIdConverter extends ClassicConverter {
private static final AtomicInteger nextId = new AtomicInteger();
private static final ConcurrentHashMap name2Id = new ConcurrentHashMap<>();
private static String getNextThreadId(String name) {
return String.format("%05d", nextId.getAndIncrement());
}
@Override
public String convert(ILoggingEvent event) {
return name2Id.computeIfAbsent(event.getThreadName(), ThreadIdConverter::getNextThreadId);
}
}
Configuration works the same way:
....
%date{HH:mm:ss.SSS},%tid,,%msg%n
N.B. This class works with AsyncAppender
, because the thread name is retrieved before going asynchronous. Also note that if threads have the same name, they will get the same id. However, this is not going to happen in practice, unless you set the same name to multiple threads on purpose, which is generally not a wise thing to do.