0

The organisation I work in uses service Now ,I just joined the team, My team wants me to do some research on logging in Service now.

All they want is to control the logging of scripts when they write a script on the server based on the verbosity level of the script

My understanding on logging is it the type of process that takes place on the server i.e

•if a script is not of a proper syntax it logs as a WARNING stating the compile error in the message of the log

•If something runs successfully or a process is completed, it logs as INFO with the message of what happened

•Similar logging for debug takes place, (I may be wrong about this though)

I tried searching on service now wiki,one method I found was gs.log()

I tried running some test script to log info in System Definition > Scripts - Background

Some of the various scripts I tried where

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


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

gs.info("This is an info log");
gs.debug("This is a debug log");

And then searched in the logs table System Logs > System Log > All

all is saw was the scripts I ran were logged as whole with INFO as the level , if the scripts had a syntax error it logged the same with WARNING level

Why doesn't it log the script line by line?

Also is there a way where I can tell Service now what script it should log based on the verbosity level?

4

1 回答 1

5

如果您使用的是 Fuji 版本或更新的版本(它仍然很新,所以您可能不是),实际上有一个全新的日志 API,它更直观,而且它是基于应用程序的。以下是该 API 的文档:

冗长

详细程度有 4 个级别,按照从最不详细到最详细的顺序,它们是:

error (gs.error)
warn (gs.warn)
info (gs.info)
debug (gs.debug)

...这意味着将特定应用程序的日志级别设置为“信息”将为您提供信息+警告+错误,但不会调试。

...会话调试详细程度为debug,因此任何级别的日志详细程度都将包含在会话调试输出中,仅用于在会话调试激活的会话中调试的应用程序。

记录详细程度的属性是(替换为您的应用程序名称):

<APP_NAME>.logging.verbosity // off -> error -> warn -> info -> debug

目的地

“db”的日志目的地会将所需日志记录详细程度内的日志消息路由到表“syslog_app_scope”,该表扩展了 syslog。这个新表添加了用于发布日志的应用程序/范围的字段以及链接到调用日志 API 的脚本的源脚本字段(当我们可以弄清楚时,目前仅用于业务规则和脚本包含)。当 Destination 设置为“db”时,日志也将转到文件系统。

“文件”的日志目的地将记录到节点的文件系统日志,而不广播到日志侦听器(脚本后台的情况除外)

目的地属性为:

<APP_NAME>.logging.destination // none -> file -> db (implies file also)

使用示例

这个 API 的使用者(来自 JavaScript)应该能够做到:

gs.debug(message [, parameters]) - 以调试级别详细程度发出日志消息

gs.info(message [, parameters]) - 以信息级别详细程度发出日志消息

gs.warn(message [, parameters]) - 以警告级别详细程度发出日志消息

gs.error(message [, parameters]) - 以错误级别详细程度发出日志消息

此日志记录 API 支持 java MessageFormat 占位符替换模式 目前最多支持 5 个“varargs”占位符参数,需要将超过 5 个指定为单个 javascript 数组参数所有这些都是合法调用:

gs.info("Here's a log message from me"); // no params
gs.info("Here's a log message from {0}", myName); // single non array param
gs.info("Here's a log message from {0}.{1}", myFirstName, myLastName); // multiple "varargs" params (up to 5!)
gs.info("Here's a log message from {0}.{1}", [myFirstName, myLastName]); // array of n-number of params (no upper bounds)
于 2015-03-27T19:00:51.080 回答