Log Levels in SuiteScript for Effective Debugging
Understand log levels in SuiteScript to filter execution messages and enhance debugging practices.
The N/log module in SuiteScript allows developers to control logging during script execution. By utilizing various log levels, developers can specify which messages are logged in the Execution Log, aiding in debugging and tracking operations effectively.
How Do Log Levels Work?
The log methods supported by the N/log module include log.debug, log.audit, log.error, and log.emergency. Each method corresponds to a specific log level that filters the output and controls the information logged. Here's a breakdown:
| Log Level | Description | Example Uses |
|---|---|---|
| Debug | Shows all messages, suitable for testing. | Use during development; avoid in production to reduce noise. |
| Audit | Records events during script processing. | "A request was made to an external site." |
| Error | Logs unexpected script errors. | Critical errors that need attention during execution. |
| Emergency | Logs only the most severe errors. | Severe failures that require immediate attention. |
When you select a log level in your script deployment, it acts as a filter for the log messages. For example, if the Log Level is set to Error, only messages created by log.error and log.emergency methods are stored, while log.audit and log.debug messages are ignored.
Best Practices for Using Log Levels
- Limit Use of Debug Level: Reserve
Debuglogging for development environments to avoid cluttering logs in production. - Audit for Monitoring: Use the
Auditlevel to maintain records of important events. - Use Conditional Logging: Implement checks to determine which log level to set based on script context (development vs. production).
How to Implement Log Levels in Your Code
Here's a simple code snippet demonstrating the use of different log levels in a User Event script:
1/**2 * @NApiVersion 2.x3 * @NScriptType UserEventScript4 */5 6define(['N/log'], function(log) {7 function beforeLoad(context) {8 var myValue = 'value';9 var myObject = { name: 'Jane', id: '123' };10 11 log.audit({12 title: 'Audit Entry',13 details: myObject14 });15 16 log.debug({17 title: 'Debug Entry',18 details: 'Value of myValue is: ' + myValue19 });20 21 log.emergency({22 title: 'Emergency Entry',23 details: 'Critical condition for: ' + myValue24 });25 26 log.error({27 title: 'Error Entry',28 details: 'Error processing value: ' + myValue29 });30 }31 return { beforeLoad: beforeLoad };32});Viewing Script Execution Logs
You can access and analyze logs by navigating to Customization > Scripting > Script Execution Logs in NetSuite. This allows users to filter logs by execution date, log level, and script name, making it easier to locate specific events. Keep in mind that logs are automatically purged after 30 days, so consider using a custom record structure if long-term storage is necessary.
Key Points to Remember
- Use the appropriate log level to manage output effectively.
- Excessive debugging in production can lead to performance issues and cluttered logs.
- Familiarize yourself with the various log methods to maximize the utility of logging in your scripts.
By understanding and utilizing log levels, you can significantly enhance your debugging capabilities within SuiteScript, making it easier to track script performance and errors.
Frequently Asked Questions (4)
What are the different log levels available in SuiteScript?
How do log levels in SuiteScript affect script execution logs?
What is the best practice for using the Debug log level in SuiteScript?
How can I access and filter SuiteScript execution logs in NetSuite?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Custom Tool Script Enhancements in NetSuite
Custom tool scripts in NetSuite gain execution log support and a new management page in February 16, 2026.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
