我有一个日志类,有几个静态方法,帮助记录有关我的程序的信息。如何知道哪个线程称为我的日志方法?
我的问题是我有2个线程正在运行,并且他们都向我的Log类发送请求以记录信息。
我想让我的日志类显示哪些线程正在记录哪些线。
我应该怎么做才能实现这个功能?
我的代码基本上是这样的:
public class Log {
public static void log (String tag , Object message)
{
String lineToPrint = "";
//Builds the string taking in time data and other information
//...
//This is where I want to see which thread called this log function
//...
System.out.println(lineToPrint);
}
}
你为什么不使用现有的日志框架之一,如log4j(可能使用apache commons logging进行包装)? – Thomas 2011-12-30 07:31:11