{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":770,"path":"api-reference/server-api-reference/GSLogBoth.md","title":"GSLog - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GSLog - Scoped, Global\n\nGSLog is a script include that simplifies script logging and debugging by implementing levels of log output, selectable by per-caller identified sys\\_properties values.\n\nLogs generated using the GSLog API are logged in the System Logs. Specifically, you can find System Logs in the UI by navigating to **All** &gt; **System Logs** &gt; **System Log**. You can choose to view all logs or specific log types like Application Logs, Errors, Script Log Statements, and so on under this menu item. Filtering the Source column in the **All** logs view can help locate your entries faster.\n\nLogs 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.\n\nUse for any server-side script where you want to implement event logging.\n\nFor more information, see [Debugging scripts](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/script-debug-overview.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GSLog – GSLog\\(\\)\n\nInstantiates a GSLog object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|traceProperty|String|System property that contains a value indicating the level at or above which messages will be written to the log.|\n|caller|String|Name of the script calling the logger.|\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\");\n```\n\n## GSLog – debugOn\\(\\)\n\nDetermines if debug is turned on.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_kyg_zmx_15b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether debug is on or off.\n\n Valid values:\n\n-   true: Debug is on.\n-   false: Debug is off.\n\n</td></tr></tbody>\n</table>```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.setLevel(\"debug\");\ngs.print(gl.debugOn());\n```\n\nOutput:\n\n```\n*** Script : true\n```\n\n## GSLog – getLevel\\(String level\\)\n\nReturns the log level.\n\n|Name|Type|Description|\n|----|----|-----------|\n|level|String|Optional. Log level.|\n\n|Type|Description|\n|----|-----------|\n|String|Log level.|\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.setLevel(\"debug\");\ngs.print(gl.getLevel());\n```\n\nOutput:\n\n```\n*** Script: debug\n```\n\n## GSLog – initialize\\(String traceProperty, String caller\\)\n\nCalled 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|traceProperty|String|System property that contains a value indicating the level at or above which messages will be written to the log.|\n|caller|String|Name of the script calling the logger.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\");\n\n```\n\n## GSLog – log\\(String level, String msg\\)\n\nLogs a message at the specified level.\n\n|Name|Type|Description|\n|----|----|-----------|\n|level|String|Log level.|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.log(\"debug\", \"debug message\");\n```\n\n## GSLog – logAlert\\(String msg\\)\n\nLogs alert events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logAlert(\"This is an alert\");\n```\n\nOutput:\n\n```\n*** Script [TaskSLA]: This is an alert\n```\n\n## GSLog – logCrit\\(String msg\\)\n\nLogs critical events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logCrit(\"This is a critical message\");\n```\n\nOutput:\n\n```\n*** Script [TaskSLA]: This is a critical message\n```\n\n## GSLog – logDebug\\(String msg\\)\n\nLogs debug events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logDebug(\"This is a debug message\");\n```\n\nOutput:\n\n```\n*** Script [TaskSLA]: This is a debug message\n```\n\n## GSLog – logEmerg\\(String msg\\)\n\nLogs emergency events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logEmerg(\"This is an emergency message\");\n```\n\nOutput:\n\n```\n*** Script  [TaskSLA ] : This is an emergency message\n```\n\n## GSLog – logErr\\(String msg\\)\n\nLogs error events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logErr(\"This is an error message\");\n```\n\nOutput:\n\n```\n*** Script [TaskSLA]: This is an error message\n```\n\n## GSLog – logInfo\\(String msg\\)\n\nLogs information events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logInfo(\"This is an info message\");\n```\n\n## GSLog – logNotice\\(String msg\\)\n\nLogs notice events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logNotice(\"This is a notice\");\n```\n\nOutput:\n\n```\n*** Script [TaskSLA]: This is a notice\n\n```\n\n## GSLog – logWarning\\(String msg\\)\n\nLogs warning events.\n\n|Name|Type|Description|\n|----|----|-----------|\n|msg|String|Message to write to the log.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.logWarning(\"This is a warning message\");\n```\n\nOutput:\n\n```\n*** Script [TaskSLA]: This is a warning message\n```\n\n## GSLog – setLevel\\(String level\\)\n\nSets the log level.\n\n|Name|Type|Description|\n|----|----|-----------|\n|level|String|Log level to set.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gl = new GSLog(\"com.snc.sla.tasksla.log\", \"TaskSLA\"); \ngl.setLevel(\"debug\");\n```\n\n"}}