我有一個日誌類,有幾個靜態方法,幫助記錄有關我的程序的信息。如何知道哪個線程稱爲我的日誌方法?
我的問題是我有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