全部,
我正在構建一個應用程序,並希望用戶能夠預覽與腳本一起自定義構建的日誌文件。 我認為這種方法將來會幫助我和用戶進行故障排除。
我認為,一種編寫方法是構建一個列表並將該列表寫成文本文件。 但我樂於接受建議,並想知道是否有更好、更清潔、更有效的方法來做到這一點。
我會只需使用保存文本文件功能追加到滾動日誌文件。 請參閱下面的示例。
// 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