Is there a way to build a custom log file in JSL ?All,
I am building an application and would like to enable the users to be able to preview a log file that is custom built along with the script. I am of the opinion that this method, will help both me and the users in the future with troubleshooting.
I think, one way to write it is by building a list and writing the list out as a text file. But I am open to suggestions and wondering if there is a better, cleaner and more efficient way to do this.
Re: Is there a way to build a custom log file in JSL ?I do something similar, here is my strategy for most projects:
- All scripts have the same log format, this means it is easy to aggregate them.
- For some add-ins logs are automatically uploaded to a central location. JMP 14 has a great method to aggregate all of these.
- I use a csv format that also stores other info, like:
- Script/Add-In Name and Version
- OS/JMP version
- Function name
- For add-ins, I load the 'writeToLog' function to a namespace for that add-in. At the top of each script I define that namespace, so in any file within that add-in I can write log messages using ns:log("message", function="foo")
Re: Is there a way to build a custom log file in JSL ?I would just use the Save Text File function to append to a rolling log file. Se example below.
// 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" );
Here's the resulting log file:
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