我需要将日志消息写入日志文件,而不是脚本中的控制台。默认情况下,openscript.info(), warn()提供的方法很少。它们在哪里配置为将消息写入控制台。当我写完info(message);的时候,它正在向控制台写入消息。log4j.properties配置在哪里?是否需要覆盖才能写入日志文件?
发布于 2016-09-05 17:52:08
所有日志消息都存储在您的OATS位置,默认位置为: C:\OracleATS\logs。文件被命名为"process_console_timestamp.hash.log“
但是,如果您想创建自己的日志文件,我建议创建一个专用的方法,它使用内置方法。在我的代码中,我做了这样的事情:
private String filePath = "c:/warnings.log";
public void saveLog(String message) throws Exception {
DateFormat df = new SimpleDateFormat("[yyyy/MM/dd HH:mm:ss]");
Date sysdate = new Date();
String modifiedText = df.format(sysdate) + " " + message + "\n";
Files.write(Paths.get(filePath), modifiedText.getBytes(),
StandardOpenOption.APPEND);
}
public void warning(String message) throws Exception {
saveLog(message);
warn(message);
}
public void run() throws Exception {
warning("Test");
}https://stackoverflow.com/questions/36125116
复制相似问题