GSLog

GSLog is a script include that simplifies script logging and debugging by implementing levels of log output, selectable by per-caller identified sys_properties values.

Log level

Logs can be at the level of Debug, Info, Notice, Warning, Err, or Crit (after BSD syslog.h and followers). The default logging level is Notice, so levels should be chosen accordingly.

Where to use

Use for any server-side script where you want to implement event logging.

Available Methods

initialize(traceProperty, caller)

Called by the Prototype JavaScript Framework during object creation to initialize a new instance of this class. Provide the input parameters, but do not call this method directly.

Table 1. Parameters
Name Type Description
traceProperty String System property that contains a value indicating the level at or above which messages will be written to the log.
caller String Name of the script calling the logger.
Table 2. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA");

logDebug(msg)

Logs debug events.

Table 3. Parameters
Name Type Description
msg String Message to write to the log
Table 4. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logDebug("This is a debug message");

Output:

*** Script [TaskSLA]: This is a debug message

logInfo(msg)

Logs information events.

Table 5. Parameters
Name Type Description
msg String Message to write to the log
Table 6. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logInfo("This is an info message");

logNotice(msg)

Logs notice events.

Table 7. Parameters
Name Type Description
msg String Message to write to the log
Table 8. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logNotice("This is a notice");

Output:

*** Script [TaskSLA]: This is a notice

logWarning(msg)

Logs warning events.

Table 9. Parameters
Name Type Description
msg String Message to write to the log
Table 10. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logWarning("This is a warning message");

Output:

*** Script [TaskSLA]: This is a warning message

logErr(msg)

Logs error events.

Table 11. Parameters
Name Type Description
msg String Message to write to the log
Table 12. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logErr("This is an error message");

Output:

*** Script [TaskSLA]: This is an error message

logCrit(msg)

Logs critical events.

Table 13. Parameters
Name Type Description
msg String Message to write to the log
Table 14. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logCrit("This is a critical message");

Output:

*** Script [TaskSLA]: This is a critical message

logAlert(msg)

Logs alert events.

Table 15. Parameters
Name Type Description
msg String Message to write to the log
Table 16. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logAlert("This is an alert");

Output:

*** Script [TaskSLA]: This is an alert

logEmerg(msg)

Logs emergency events.

Table 17. Parameters
Name Type Description
msg String Message to write to the log
Table 18. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logEmerg("This is an emergency message");

Output:

*** Script  [TaskSLA ] : This is an emergency message

log(level, msg)

Logs a message at the specified level.

Table 19. Parameters
Name Type Description
level String Log level
msg String Message to write to the log
Table 20. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.log("debug", "debug message");

getLevel(level)

Returns the log level.

Table 21. Parameters
Name Type Description
level String Optional. Log level
Table 22. Returns
Type Description
String Log level

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.setLevel("debug");
gs.print(gl.getLevel());

Output:

*** Script: debug

setLevel(level)

Sets the log level.

Table 23. Parameters
Name Type Description
level String Log level to set
Table 24. Returns
Type Description
void

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.setLevel("debug");

debugOn()

Determines if debug is turned on.

Table 25. Parameters
Name Type Description
none
Table 26. Returns
Type Description
Boolean If true, debug is on; if false, debug is off.

Example

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.setLevel("debug");
gs.print(gl.debugOn());

Output:

*** Script : true