是否可以更改安装日志记录的输出格式,例如:[日期]|[时间]|[内容]?
或者是否可以包含 commons-logging 或 log4j 进行格式化输出?
最佳答案
从 5.1.x 开始,这是不可能的。计划在未来版本中添加自动时间戳。
您可以在安装程序的“启动”节点的“运行脚本”操作中注册安装程序事件监听器以写入时间戳:
import java.text.SimpleDateFormat;
import java.text.DateFormat;
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
context.addInstallerEventListener(new InstallerEventListener() {
public void installerEvent(InstallerEvent event) {
if (event.getType() == EventType.BEFORE_EXECUTE_ACTION) {
Util.logInfo(event.getSource(), "Started action at " +
dateFormat.format(new Date()));
} else if (event.getType() == EventType.AFTER_EXECUTE_ACTION) {
Util.logInfo(event.getSource(), "Finished action at " +
dateFormat.format(new Date()));
}
}
});
关于java - 如何自定义安装日志文件的日志输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26357313/