ServiceNow's logging methods write to the system log table (syslog) with different severity levels that control visibility and retention. Most developers use gs.log() for everything, but the platform treats debug, info, warn, and error messages differently β debug messages are filtered by default in production, while error messages trigger monitoring alerts. The biggest mistake is logging inside loops over query results, which creates thousands of identical log entries that overwhelm the system and make real issues impossible to find.
When to use this
- When debugging complex Business Rules or Script Includes that process records with multiple state transitions
- When tracking integration failures or unexpected API responses that need administrator attention
- When validating business rule execution in Scheduled Jobs that run unattended
- When creating audit trails for high-value record changes that bypass standard audit tables
When NOT to use this
- Don't log inside
while(gr.next())loops β log the count or summary instead - Don't use this for user-facing messages β use
gs.addInfoMessage()orgs.addErrorMessage()instead - Don't log in Client Scripts β system logs are server-side only, use browser console instead
- Don't log sensitive data like passwords or API keys β system logs are readable by system administrators
Key behaviors and gotchas
gs.log()writes debug level messages β filtered out by default in production instancesgs.info()is always visible and should be your default for application flow trackinggs.warn()andgs.error()can trigger monitoring alerts depending on instance configuration- The source parameter is optional but critical for filtering logs β use your script name or table name
- Log messages are truncated at 4000 characters β split long messages or use
JSON.stringify()for objects - System logs respect domain separation β messages only visible to users in the same domain
Logging in tight loops will flood your system logs and make debugging impossible. A Business Rule that logs inside a query loop can generate thousands of identical messages. Always log summaries, counts, or move logging outside the loop.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros β scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.