Contents Hide
str1 = "To ERROR";
ScriptSession.logError(str1);
str2 = "To INFO";
ScriptSession.logInfo(str2);
str3 = "To DEBUG";
ScriptSession.logDebug(str3);
Note:
str1, str2 and str3 will be printed in the error, info and debug streams of the BrightServer log respectively.
Below is a fragment of code from a script which throws two types of errors, depending if a given number is too large or too small. It uses the ScriptSession object to store exception details in this process, as otherwise the information will be lost.
try
{
if (q < 0) throw ("Err1");
if (q > 30) throw ("Err2");
}
catch (e)
{
if (e == "Err1")
ScriptSession.setError(100,"Number too small");
if (e == "Err2")
ScriptSession.setError(101,"Number too large");
}
Note:
q - variable which may throw errors, depending on the size.
100, 101 - error codes corresponding to the error caught.
The following code is used to print out the last error recorded by the ScriptSession object, into a BrightServer's log under the ERROR stream.
ScriptSession.logError("ERROR " + ScriptSession.getLastError());
Note:
the last error printed depends on what the last error that was recorded using the setError() method. If no method was set in this fashion, the string retrieved will be empty.
In some occasions, it may useful to capture log entries when a process is being executed (e.g. processing incoming files or executing a specific business logic), and persist them separately for filing and/or sending the captured logs files, for instance, in emails.
ScriptSession.startLogging("c:\\temp\\last_run.log") ;
// ... Excute logic and capture log by using ScriptSession methods
...
ScriptSession.stopLogging() ;
Note:
Log directory in this example is arbitrarily selected to be "c:\temp" directory on a Windows machine.
The log file will capture all of the log entries stored into the server log files that includes the user log entries created by the ScriptSession logging methods.