The N/log module is used to write log entries to the NetSuite Script Execution Log. It is an indispensable debugging and monitoring tool for every SuiteScript developer. Logs are viewable at Customization > Scripting > Script Execution Logs.
Log Levels
| Method | Log Level | Use Case | Governance |
|---|---|---|---|
log.debug() | DEBUG | Development β detailed output | 10 units |
log.audit() | AUDIT | Production β key events | 10 units |
log.error() | ERROR | Caught errors, exceptions | 10 units |
log.emergency() | EMERGENCY | Critical system failures | 10 units |
Using N/log
define(["N/log"], (log) => {
log.debug({ title: "Script Started", details: "User event triggered" });
log.audit({ title: "Record Saved", details: "Customer ID: 12345" });
log.error({ title: "Error occurred", details: JSON.stringify(error) });
log.emergency({ title: "CRITICAL", details: "Unexpected failure in sync process" });
return {};
});
Best Practices
Set the log level on your Script Deployment to DEBUG during development and AUDIT in production. Each log call costs 10 governance units, so avoid logging inside high-frequency loops. Use log.audit() in production as it is the least disruptive level that still records key milestones. Always include meaningful titles and detailed messages to make debugging easier.