Close
Thank you for your feedback.

GSLog

GSLog is a script include which makes logging and debugging from script easier 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 would normally be Notice, so levels should be chosen accordingly.

Where to use

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

Methods

Method Description Input Fields Output Fields Example
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. Parameters:
  • traceProperty - A system property that contains a value indicating the level at or above which messages will be written to the log.
  • caller - The name of the script calling the logger.
Returns: void
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA");
logDebug(msg) Logs debug events. Parameters: msg - The message to write to the log. Returns: void
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. Parameters: msg - The message to write to the log. Returns: void
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.logInfo("This is an info message");
logNotice(msg) Logs notice events. Parameters: msg - The message to write to the log. Returns: void
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. Parameters: msg - The message to write to the log. Returns: void
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. Parameters: msg - The message to write to the log. Returns: void
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. Parameters: msg - The message to write to the log. Returns: void
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. Parameters: msg - The message to write to the log. Returns: void
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. Parameters: msg - The message to write to the log. Returns: void
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. Parameters:
  • level - The log level.
  • msg - The message to write to the log.
Returns: void
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.log("debug", "debug message");
setLevel(level) Sets the log level. Parameters: level - The log level. Returns: void
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.setLevel("debug");
getLevel(level) Gets the log level. Parameters: level - (optional) The log level. Returns: The log level.
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.setLevel("debug");
gs.print(gl.getLevel());

Output:

*** Script: debug
debugOn() Determines if debug is turned on. Parameters: N/A Returns: (boolean) If true, debug is on; if false, debug is off.
var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA"); 
gl.setLevel("debug");
gs.print(gl.debugOn());

Output:

*** Script : true

Products > ServiceNow Platform > Scripting; Versions > Istanbul