【问题标题】:Write log messages to the log file in openscript将日志消息写入openscript中的日志文件
【发布时间】:2016-03-21 07:18:48
【问题描述】:

我需要将日志消息写入日志文件而不是脚本中的控制台。 默认情况下,openscript.info(), warn() 提供的方法很少。 他们在哪里配置将消息写入控制台。 当我写info(message); 时,它正在向控制台写入消息。 log4j.properties 在哪里配置?我是否需要重写才能写入日志文件?

【问题讨论】:

    标签: openscript


    【解决方案1】:

    所有日志消息都存储在您的 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");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2019-02-04
      • 2019-03-14
      相关资源
      最近更新 更多