N/log Module for Script Execution Logging in NetSuite
The N/log module enables script execution logging in NetSuite, enhancing debugging and performance monitoring for developers.
The N/log module provides developers with a way to log script execution details, which is crucial for debugging and performance tracking. Utilizing this module allows both client and server scripts to record important operational events, thus helping in maintaining application integrity and reliability.
What Is the N/log Module?
The N/log module is designed for manually accessing methods that log execution details of your scripts. You can also access these methods via the global log object. Log messages are recorded on the Execution Log subtab of the script deployment and can be viewed in the Script Execution Logs page under Customization > Scripting > Script Execution Logs. This facility allows you to keep track of various execution attributes effectively.
N/log Module Guidelines
When using the N/log module, it’s important to keep the following guidelines in mind:
- NetSuite limits logging to 100,000 log object method calls every 60 minutes across all scripts in a company, preventing excessive logging from any single script.
- Logs older than 30 days are purged from the system.
- Each customer has a log storage limit of 5 million entries in the server script log search and execution logs tab, which means message persistence is not guaranteed unless custom records are used for longer retention.
- Error messages and notes from NetSuite appear in the Execution Log, which is useful for debugging purposes.
- If a client script using the N/log module is attached to a form, the log messages will be ignored. Instead, it is recommended to use
console.logfor form-attached client scripts. - When logging objects, NetSuite automatically converts them to JSON string format before logging.
Using Log Levels
The logging methods in the N/log module can be utilized along with the Log Level field in the script deployment to filter log messages. This is beneficial for debugging scripts or for tracking script usage. The available log levels include:
- Debug: Logs all messages; suitable for testing but should not be employed in production scripts due to potential for excessive logging.
- Audit: Documents events, providing a record of significant occurrences during script processing.
- Error: Captures unexpected errors encountered within the script.
- Emergency: Logs only the most critical errors that require immediate attention.
Viewing Script Execution Logs
Log messages generated by client scripts tied to forms are accessible through the browser's debug console. For server scripts, logs can be reviewed via the Script Execution Logs page. Features of this page include:
- Filters to search logs based on level, date, and script name.
- Options to download or print logs.
N/log Module Members
The N/log module contains several important methods:
| Member Type | Name | Return Type | Supported Script Types | Description |
|---|---|---|---|---|
| Method | log.audit(options) | void | Client and server scripts | Logs an Audit message. |
| Method | log.debug(options) | void | Client and server scripts | Logs a Debug message. |
| Method | log.emergency(options) | void | Client and server scripts | Logs an Emergency message. |
| Method | log.error(options) | void | Client and server scripts | Logs an Error message. |
Example of Using N/log
Here’s a script example demonstrating logging:
1/**2 * @NApiVersion 2.x3 * @NScriptType UserEventScript4 */5 6define(['N/log'], function(log) {7 function beforeLoad(context) {8 var myValue = 'value';9 10 var myObject = {11 name: 'Jane',12 id: '123'13 };14 15 log.audit({16 title: 'Audit Entry',17 details: myObject18 });19 20 log.debug({21 title: 'Debug Entry',22 details: 'Value of myValue is: ' + myValue23 });24 25 log.emergency({26 title: 'Emergency Entry',27 details: 'Value of myValue is: ' + myValue28 });29 30 log.error({31 title: 'Error Entry',32 details: 'Value of myValue is: ' + myValue33 });34 }35 return {36 beforeLoad: beforeLoad37 };38});Key Takeaways
- The N/log module enhances script debugging and logging capabilities.
- Utilize log levels to manage logging output effectively.
- Be aware of NetSuite's limits on logging to optimize performance and error management.
- Client scripts attached to forms require
console.logfor logging instead of N/log methods.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Does the N/log module apply to both client and server scripts in NetSuite?
What are the limitations on logging with the N/log module in NetSuite?
How should logging be handled for client scripts attached to forms?
What happens to log messages if the log storage limit is reached?
Was this article helpful?
More in General
- Payment Date Prediction Feature in NetSuite
Payment Date Prediction in NetSuite utilizes machine learning to enhance financial planning by predicting invoice payment dates.
- NetSuite Ship Central Enhancements for Packing & Shipping
NetSuite Ship Central features enhance packing and shipping operations for improved efficiency and accuracy.
- New Role Setup for NetSuite AI Connector Service in 2026.1
The 2026.1 release adds a new role requirement for the NetSuite AI Connector Service, streamlining custom tool development.
- Generative AI Features in NetSuite 2026.1
Discover new generative AI features in NetSuite 2026.1, enhancing reporting, search, predictions, and development productivity.
Advertising
Reach General Professionals
Put your product in front of NetSuite experts who work with General every day.
Sponsor This Category