ScriptSession Examples

Contents Hide

  

Example 1. Logging with scripts

str1 = "To ERROR";

ScriptSession.logError(str1);

str2 = "To INFO";

ScriptSession.logInfo(str2);

str3 = "To DEBUG";

ScriptSession.logDebug(str3);

Note:

Example 2. Recording Errors

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:

Example 3. Retrieving Errors

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:

Example 4. Capturing log entries into a dedicated file

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: