全部,
我正在构建一个应用程序,并希望用户能够预览与脚本一起自定义构建的日志文件。 我认为这种方法将来会帮助我和用户进行故障排除。
我认为,一种编写方法是构建一个列表并将该列表写成文本文件。 但我乐于接受建议,并想知道是否有更好、更清洁、更有效的方法来做到这一点。
我会只需使用保存文本文件功能追加到滚动日志文件。 请参阅下面的示例。
// some variables to show
x = 5;
y = 10;
z = 25;
// path to the log
logFilePath = "$TEMP/MyJmpAddin2.log";
// initialize the log in case it doesnt exist
If( !File Exists( logFilePath ), Save Text File( logFilePath, "" ) );
// function to write to the log file (with a new line character at the end)
writeToLog = Function( {str},
Save Text File(
logFilePath,
Format( Today(), "m/d/y h:m:s" ) || " - " || str || "\!N",
Mode( "append" )
)
);
writeToLog( "showing x in JMP log" );
show( x );
writeToLog( "showing y in JMP log" );
show( y );
writeToLog( "showing z in JMP log" );
show( z );
// for demonstration purposes, open the log file as plain text
Open( logFilePath, "plain text" );
这是生成的日志文件:
01/31/2018 1:56:23 PM - showing x in JMP log
01/31/2018 1:56:23 PM - showing y in JMP log
01/31/2018 1:56:23 PM - showing z in JMP log