top of page

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

Understanding the Difference Between gs.log() and gs.print() in ServiceNow

Updated: Mar 28

ServiceNow developers frequently encounter the methods gs.log() and gs.print() when scripting. While both functions are used to output messages, understanding their differences can significantly enhance your debugging efficiency and clarity. This article explains the distinction between these two commonly used functions, clarifies their best use cases, and provides practical guidance for ServiceNow scripting.


What is the Difference Between gs.log() and gs.print()?

Both gs.log() and gs.print() methods are used to send messages or debugging information, yet each serves a different purpose within the ServiceNow platform.

gs.log():

The gs.log() function records messages in the ServiceNow syslog table, accessible via the navigation bar under System Logs > System Log. In on-premise environments, these logs may also be written to application logs, such as Tomcat logs.

This function accepts two parameters:

gs.log("Your log message", "SourceCategory");

The second parameter, "SourceCategory", allows you to categorize log entries for easier filtering and analysis.


gs.print():

In contrast, gs.print() is primarily used when executing scripts in Scripts - Background:

  • Screen Output: gs.print() directly displays messages in the output console after script execution but does not work in server-side scripts such as business rules, workflows, or scheduled jobs.

  • Temporary Logging: Messages displayed using gs.print() are not persistently stored in the syslog table, making it suitable only for real-time debugging and temporary use.

This function takes a single parameter:

gs.print("This is a test message");

Practical Examples and Use Cases

Example of gs.log():

When troubleshooting a scheduled job or workflow activity that runs without immediate visual feedback, using gs.log() is ideal:

This helps track job execution in system logs with clear identification through the specified source.


Example of gs.print():

For quickly checking script results in a one-time execution via Scripts - Background, gs.print() is ideal:

This output appears directly on the screen immediately after execution, simplifying the debugging process.


Alternative Solutions

In scoped applications, note that gs.log() does not function. In such scenarios, use gs.info() as an effective alternative:

gs.info("Scoped app log message");

This method reliably logs messages in scoped applications, functioning similarly to gs.log() by recording entries in the syslog table.


Summary and Next Steps

In summary, use gs.log() for structured logging and persistent record-keeping, especially beneficial for ongoing monitoring and troubleshooting within the platform. Conversely, use gs.print() for immediate, ephemeral debugging output during script execution from the background scripts.

To further enhance your ServiceNow scripting skills, consider:

  • Regularly reviewing your logs for optimized system performance.

  • Clearly defining log sources in gs.log() for better categorization and analysis.

  • Transitioning to gs.info() when working with scoped applications for consistent logging.


Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page