---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GSLog - Scoped, Global

# GSLog - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

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.

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.

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

For more information, see [Debugging scripts](https://www.servicenow.com/docs/access?context=script-debug-overview&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US).

## GSLog -- GSLog() {#ariaid-title2}

Instantiates a GSLog object.
{#gsLog-GSLog__table_bln_fyx_15b__entry__3}

| 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 1. Parameters]

{#gsLog-GSLog__table_bln_fyx_15b}  

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

## GSLog -- debugOn() {#ariaid-title3}

Determines if debug is turned on.
{#gsLog-debugOn__table_jyg_zmx_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 2. Parameters]

{#gsLog-debugOn__table_jyg_zmx_15b} {#gsLog-debugOn__table_kyg_zmx_15b__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether debug is on or off. Valid values: * true: Debug is on. * false: Debug is off. {#gsLog-debugOn__ul_zcc_gxx_15b} |
[Table 3. Returns]

{#gsLog-debugOn__table_kyg_zmx_15b}  

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

Output:

    *** Script : true

## GSLog -- getLevel(String level) {#ariaid-title4}

Returns the log level.
{#gsLog-getLevel_S__table_tpq_j4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| level | String | Optional. Log level. |
[Table 4. Parameters]

{#gsLog-getLevel_S__table_tpq_j4x_15b} {#gsLog-getLevel_S__table_upq_j4x_15b__entry__2}

| Type | Description |
|-|-|
| String | Log level. |
[Table 5. Returns]

{#gsLog-getLevel_S__table_upq_j4x_15b}  

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

Output:

    *** Script: debug

## GSLog -- initialize(String traceProperty, String caller) {#ariaid-title5}

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.
{#gsLog-initialize_S_S__table_gjz_1nx_15b__entry__3}

| 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 6. Parameters]

{#gsLog-initialize_S_S__table_gjz_1nx_15b} {#gsLog-initialize_S_S__table_hjz_1nx_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 7. Returns]

{#gsLog-initialize_S_S__table_hjz_1nx_15b}  

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

## GSLog -- log(String level, String msg) {#ariaid-title6}

Logs a message at the specified level.
{#gsLog-log_S_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| level | String | Log level. |
| msg | String | Message to write to the log. |
[Table 8. Parameters]

{#gsLog-log_S_S__table_sz4_m4x_15b} {#gsLog-log_S_S__table_jdw_k4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 9. Returns]

{#gsLog-log_S_S__table_jdw_k4x_15b}  

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

## GSLog -- logAlert(String msg) {#ariaid-title7}

Logs alert events.
{#gsLog-logAlert_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 10. Parameters]

{#gsLog-logAlert_S__table_sz4_m4x_15b} {#gsLog-logAlert_S__table_oh5_l4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 11. Returns]

{#gsLog-logAlert_S__table_oh5_l4x_15b}  

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

Output:

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

## GSLog -- logCrit(String msg) {#ariaid-title8}

Logs critical events.
{#gsLog-logCrit_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 12. Parameters]

{#gsLog-logCrit_S__table_sz4_m4x_15b} {#gsLog-logCrit_S__table_tz4_m4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 13. Returns]

{#gsLog-logCrit_S__table_tz4_m4x_15b}  

    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

## GSLog -- logDebug(String msg) {#ariaid-title9}

Logs debug events.
{#gsLog-logDebug_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 14. Parameters]

{#gsLog-logDebug_S__table_sz4_m4x_15b} {#gsLog-logDebug_S__table_tz4_m4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 15. Returns]

{#gsLog-logDebug_S__table_tz4_m4x_15b}  

    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

## GSLog -- logEmerg(String msg) {#ariaid-title10}

Logs emergency events.
{#gsLog-logEmerg_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 16. Parameters]

{#gsLog-logEmerg_S__table_sz4_m4x_15b} {#gsLog-logEmerg_S__table_fbm_n4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 17. Returns]

{#gsLog-logEmerg_S__table_fbm_n4x_15b}  

    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

## GSLog -- logErr(String msg) {#ariaid-title11}

Logs error events.
{#gsLog-logErr_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 18. Parameters]

{#gsLog-logErr_S__table_sz4_m4x_15b} {#gsLog-logErr_S__table_kzj_44x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 19. Returns]

{#gsLog-logErr_S__table_kzj_44x_15b}  

    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

## GSLog -- logInfo(String msg) {#ariaid-title12}

Logs information events.
{#gsLog-logInfo_S__table_e4f_p4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 20. Parameters]

{#gsLog-logInfo_S__table_e4f_p4x_15b} {#gsLog-logInfo_S__table_f4f_p4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 21. Returns]

{#gsLog-logInfo_S__table_f4f_p4x_15b}  

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

## GSLog -- logNotice(String msg) {#ariaid-title13}

Logs notice events.
{#gsLog-logNotice_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 22. Parameters]

{#gsLog-logNotice_S__table_sz4_m4x_15b} {#gsLog-logNotice_S__table_kdc_q4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 23. Returns]

{#gsLog-logNotice_S__table_kdc_q4x_15b}  

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

Output:

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

## GSLog -- logWarning(String msg) {#ariaid-title14}

Logs warning events.
{#gsLog-logWarning_S__table_sz4_m4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| msg | String | Message to write to the log. |
[Table 24. Parameters]

{#gsLog-logWarning_S__table_sz4_m4x_15b} {#gsLog-logWarning_S__table_fwt_s4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 25. Returns]

{#gsLog-logWarning_S__table_fwt_s4x_15b}  

    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

## GSLog -- setLevel(String level) {#ariaid-title15}

Sets the log level.
{#gsLog-setLevel_S__table_tpq_j4x_15b__entry__3}

| Name | Type | Description |
|-|-|-|
| level | String | Log level to set. |
[Table 26. Parameters]

{#gsLog-setLevel_S__table_tpq_j4x_15b} {#gsLog-setLevel_S__table_fwt_s4x_15b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 27. Returns]

{#gsLog-setLevel_S__table_fwt_s4x_15b}  

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


