The CreatorCon Call for Content is officially open! Get started here.

Logger script include

karthik65
Tera Guru

The use of getsystemlogger in Script include. 

And i want to replace gs.debug by a Logger method. please provide inputs.

2 REPLIES 2

HIROSHI SATOH
Mega Sage

Understanding getsystemlogger and Replacing gs.debug

 

getsystemlogger: This method in ServiceNow returns a Logger object, providing a more structured and flexible way to log messages within your scripts. It offers various log levels (e.g., debug, info, warn, error) and allows you to customize the log output.


Replacing gs.debug: While gs.debug is a simpler method for basic debugging, getsystemlogger offers more granular control over logging. To replace gs.debug, you would typically call the debug() method on the Logger object.

 

Example:

var logger = new GlideSystem().getLogger('your_application_name');

// Replace gs.debug with logger.debug
logger.debug('This is a debug message');
logger.info('This is an informational message');
logger.warn('This is a warning message');
logger.error('This is an error message');

 

Benefits of using getsystemlogger:

Customization: You can configure the logger to output to different destinations (e.g., syslog, a file, a database) and customize the format of log messages.


Granularity: Different log levels allow you to control the amount of information logged.
Performance: Depending on the configuration, using a logger can be more efficient than using gs.debug for large amounts of logging.

karthik65
Tera Guru

I cannot use New Glide system in Scoped application. I am having a script include for the methods. what can i do?