What It Does

The gs.log() method writes a message directly to ServiceNow's system log table (syslog). Each call creates a new log record with a timestamp, source label, and your message. This is the primary mechanism for debugging server-side scripts in ServiceNow.

Internally, ServiceNow creates a new record in the syslog table with your message in the message field, your source parameter in the source field, and sets the log level to INFO. The platform automatically adds the timestamp and session information.

The method returns void - it doesn't return any value. It either succeeds silently or fails silently. There's no way to know if the log write failed except by checking the system logs themselves.

The message parameter gets converted to a string if you pass other data types. Objects and arrays get their toString() representation, which usually isn't helpful. For objects, explicitly convert to JSON first.

This method is related to gs.debug(), gs.info(), gs.warn(), and gs.error(), but those methods don't accept a source parameter and have different log levels. Use gs.log() when you need to categorize your log messages with custom source labels.

When to Use This

Use gs.log() when debugging server-side scripts during development or when you need to trace execution flow in Business Rules, Script Includes, or Scheduled Jobs. The source parameter makes it ideal for distinguishing between different parts of your application or different developers' debug messages.

Avoid using gs.log() inside loops in production code - each call creates a database record and will impact performance. For production error handling, use gs.error() instead. For client-side debugging, use browser console methods or jslog() in client scripts.

Common misuse includes leaving debug gs.log() calls in production code, using it for user-facing error messages (use notifications instead), or logging sensitive data like passwords or API keys to the system log where other admins can see them.

Return Value

The method returns void (undefined in JavaScript terms). There is no return value to capture or check. The method either writes the log entry successfully or fails silently - you won't know which happened without checking the system logs.

Don't assign the result to a variable or chain other methods after gs.log() - it will be undefined. Simply call it as a standalone statement.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

Platform Behavior & Side Effects

  • Creates a new record in the syslog table with each call - this is a database write operation
  • Does not trigger Business Rules, ACLs, or notifications on the syslog table - it's a direct insert
  • Performance impact is minimal for occasional use but significant in high-volume loops
  • Log entries are not cached - each call hits the database immediately
  • Works identically in Business Rules (before/after), Script Includes, Scheduled Jobs, and Transform Maps
  • Log records respect data retention policies - old log entries get automatically purged
⚠️

Log entries are visible to all users with access to System Logs > All. Never log sensitive information like passwords, API keys, or personal data.