【发布时间】:2023-03-29 07:08:02
【问题描述】:
我有一个 Log 类,它有几个静态方法可以帮助记录有关我的程序的信息。
我的问题是我有 2 个线程正在运行,它们都向我的 Log 类发送请求以记录信息。
我想让我的 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 包装)?
标签: java multithreading logging