Logging in Scoped Applications

Logging has always been a bit of a pain in ServiceNow.  Back in the day we had gs.log primarily, mostly replaced with gs.info these days.  There was also an API called GSLog that allowed us to create a custom property to control the logging level that we wanted to log, which was a definite step forward.

Scoped Applications take this to another level, but there is VERY little information available out there on it, and even less people talking about this. Here it is:

SCOPED APPLICATIONS HAVE BUILT IN FUNCTIONALITY FOR LOGGING LEVELS!

Yes, you read that correctly.  There are a couple of properties that a Scoped Application will automatically look for in order to determine your log level.  

Why does this matter?

Using gs.info is just one of many logging methods that we can use, but it is the most common by far.  The problem with this? We overwhelm the log when we leave what would technically be debugging logs in our applications because we used gs.info.  Or we need to go back and remove the gs.info calls that we didn't really want to leave in our application. 

Fortunately, Scoped Applications give us built in functionality to allow for setting the logging level of our application (debug, info, warn, or error), and we can then leave our debugging logs in our application for when the app actually needs to be debugged.  

"logging.verbosity"

The logging property that you can create in your Scoped Application is called "logging.verbosity." Take note, when you create this in your Scoped Application, it will be prefixed with your scope prefix, this IS what you want.

From the Docs:

 

Log Level

Description

error (gs.error)

Logs events that might still allow the application to continue running. Setting the log level for an application to error generates error messages only, but does not generate warn, info, or debug messages. 

warn (gs.warn)

Logs potentially harmful events. Setting the log level for an application to warn generates error and warn messages, but does not generate error or debug messages.

info (gs.info) 

Logs informational messages that describe the progress of the application. Setting the log level for an application to info generates info, warn, and error messages, but does not generate debug messages. 

debug (gs.debug) 

Logs informational events that are useful for debugging an application. Setting the log level for an application to debug generates info, warn, error, and debug messages.

 

When creating this property for a scoped application, the following fields in the System Property record should also be filled out as indicated:

Suffix: logging.verbosity
(This holds the property name that is to be configured for the scoped application)

Name: This will automatically populate after suffix is filled out (scope_name.logging.verbosity)
Example" If the scoped app name is x_sn_newapp, then it would be x_sn_newapp.logging.verbosity.

Application: The will auto populate with the name of the scoped app.

Description: This is an optional field which is used to hold the purpose and usage of this system property.

Choicesdebug,info,warn,error
(This field should hold the options which can be selected for the property with a comma in between each allowable setting for the property)

Typechoice list (as selected from the pull down menu)

Value: This should be one of the strings (error, warn, info, or debug) as described above.

The Ignore Cache and Private checkboxes should both be selected for this system property.

Application Logs

One of the greatest benefits of this is the detail you can get from the newer Application Logs (vs just Logs).  The Application Logs will give you information about the exact location that the logging occurred.

 

Conclusion

In short, logging is key to debugging any application. By using the logging.verbosity property in a Scoped Application, you gain the ability to leave different levels of logging in your application, making it easier to debug in the future when things go awry. 

Utilizing this property allows you to leave your gs.debug, gs.info and other messages in your code for future debugging purposes.  

 

 

Comments are closed