An Adobe ExtendScript compatible log file constructor with some built in convenience functions in a UMD wrapper for cross-compatability with AMD and node.js require.
Tries to be flexible but automate most things.
- Works with node.js require, AMD(probably), and vanilla ExtendScript.
- Tries to make a log file in ./logs with fallback to ~/Desktop/ExtendScript_Log_UnsavedScripts/
- Tries to clean up old files automatically (or keep them foreverrr)
- Plays nice with ExtendScript_Log
If running Node NPM, you can npm install ExtendScript_Log
to add to your node_modules folder
Clone or download the repo and copy the extendscript_logfile.jsxinc to your project
var LogFile = require("ExtendScript_LogFile");
I don't know but it's probably not difficult? Firmly in the untested-but-should-work category
$.evalFile("<path>/extendscript_logfile.jsxinc")
//@include "<path>/extendscript_logfile.jsxinc"
Add to a build script or, I dunno, just copy-pasta it in there?
make a new log file and you get a separate instance
var myLogFile = new ExtendScript_LogFile();
myLogFile.log('Hey there.');
"new" constructor takes 4 optional arguments.
new ExtendScript_LogFile (root, logType, logDir, useDate)
is an alternate root object to tack on a 'logFile' alias By passing $.global as first arg, we get global log and console objects!
root = $.global;// root to add convenience aliases to
var myExplicitLogFileVariable = new ExtendScript_LogFile(root);
myExplicitLogFileVariable.log('So explicit!');// call from a var
logFile.log('Like magic.');// uses the $.global.logFile we made
specifies a non-"default" type and makes a file name
var myLogFile = new ExtendScript_LogFile();
myLogFile.log('Hey there.');
var specialLogFile = new ExtendScript_LogFile(null,"special");
specialLogFile.log('Salutations.');
// prints to:
// ./logs/default_2021-05-28T16-15-37.611.log >>[2021-05-28T16:15:37.612] default : Hey there.
// ./logs/special_2021-05-28T16-15-37.656.log >>[2021-05-28T16:15:37.657] special : Salutations.
a non-"default" directory path to save the log to
root = $.global;// root to add convenience aliases to
logType = "special";// name other than "default"
logDir = '~/Desktop/mylogcabin/';// custom log directory
var myLogFile = new ExtendScript_LogFile(root, logType, logDir);
myLogFile.log('Salutations.');
// prints to:
// ~/Desktop/mylogcabin/special_2021-05-28T16-15-37.656.log >>[2021-05-28T16:15:37.657] special : Salutations.
specifies if the date should be prepended to the log entries
can be changed with .useDate(false)
root = $.global;// root to add convenience aliases to
logType = "special";// name other than "default"
logDir = '~/Desktop/mylogcabin/';// custom log directory
useDate = false;
var myLogFile = new ExtendScript_LogFile(root, logType, logDir, useDate);
myLogFile.log('Salutations.');
// prints to:
// ~/Desktop/mylogcabin/special_2021-05-28T16-15-37.656.log >> special : Salutations.
.log()
and .writeln()
do the same thing...
.useDate(false)
will disable the date printing in each entry
myLogFile = new ExtendScript_Log($.global);
logFile.log('Messages are good.');
var namespace = {};// maybe some other log system?
myLogSafeFile = new ExtendScript_Log(namespace);
namespace.logFile.log('This is way safer.');
You can .clear()
the contents or .remove()
the file from disk.
You can also clear out of the same type with .removeOld()
for non-current or .removeAll()
for all.
myLogFile = new ExtendScript_Log();
logfile.log('Messages are good.');
myLogSafeFile = new ExtendScript_Log(namespace,'special');
namespace.logFile.log('This is way safer.');
myLogSafeFile.remove();
// make a bunch of "default" logs...
myLogFile = new ExtendScript_Log();
myLogFile = new ExtendScript_Log();
myLogFile = new ExtendScript_Log();
myLogFile = new ExtendScript_Log();
// purge all but latest "default" log.
myLogFile.removeOld();
// now only the current "default" file is left
myLogFile.removeAll();
myLogSafeFile = new ExtendScript_Log(namespace);
Tries to make a log file in ./logs in the location of the currently running script, but will fall back to ~/Desktop/ExtendScript_Log_UnsavedScripts/
This is used as a optional extra in ExtendScript_Log
Like peanutbutter and chocolate...