The Log Class allows applications to log debug, informational, and error information that is produced during the course of execution of a script. Log entries can have different levels of severity. There are five different levels, in order of least severe to most severe: Debug, Info, Warn, Error, and Fatal. The log output may optionally be filtered, so that only desired error levels are placed into the output log file.
// Log appends timestamped, severity-tagged lines to a file:
//
// Sat Aug 16 09:14:02 2025 - [warn ] disk is nearly full
//
// The file is opened for appending, never truncated, so runs accumulate.
// (Environment.getTempPath() has no trailing separator)
const path = `${Environment.getTempPath()}/example.log`;
// the filename can go to the constructor, or to a later open(path) call
const log = new Log(path);
// start clean; erase() reopens the file, so the handle stays usable
log.erase();
// the five levels, least to most severe; each takes any number of
// arguments and writes one line per argument
log.debug("connecting");
log.info("connected", "schema version 14");
log.warn("query took 4.2 seconds");
log.error("could not write the summary table");
log.fatal("giving up");
// setFilterLevel() decides what reaches the file from here on. The
// levels are bit flags; anything filtered out is dropped and the call
// returns false. Log.LevelAll is the state a new Log starts in.
log.setFilterLevel(Log.LevelWarn | Log.LevelError | Log.LevelFatal);
const wrote_info = log.info("filtered out");
log.warn("still gets through");
log.close();
// read it back
let output = `${path}\n\n`;
const reader = File.openText(path);
let line;
while ((line = reader.readLine()) !== null) {
output += `${line}\n`;
}
reader.close();
alert(`${output}\ninfo() while filtered returned ${wrote_info}`); True upon success, false otherwise
Closes the log file
True upon success, false otherwise
Adds a debug output line to the log
True upon success, false otherwise
Calling Log.erase() truncates the log file to zero lines. This is useful for resetting the log file for a new set of output.
True upon success, false otherwise
Adds an error output line to the log
True upon success, false otherwise
Adds a fatal output line to the log
True upon success, false otherwise
Adds an information output line to the log
True upon success, false if the open operation failed
Calling open() opens a log file for appending. If the log file does not already exist, it is created. If it already exists, it it appended to, not truncated.
If setConsoleOutput() is activated, all log lines that appear in the log file also appear in console output.
Undefined
Calling setFilterLevel() enables you to direct the log class to only output certain log entries. For instance, calling setLogLevel with the Log.LevelDebug parameter would cause only subsequent debug() messages to be inserted into the log output file. These levels may be combined with a bitwise or mask.
True upon success, false otherwise
Adds a warning output line to the log