<img src="https://ws.zoominfo.com/pixel/5BFMW73xT6Cu70sN1cUt" width="1" height="1" style="display: none;">

Understanding the NetSuite N/log Module

Posted by Steven Chao on Mar 27, 2025 9:30:00 AM
Steven Chao

Understanding the NetSuite N log Module

Error Tracking and Debugging in NetSuite

(This article is based on SuiteScript 2.1)

The N/log module is an essential tool for logging messages and debugging scripts.
It provides structured logging methods to help developers track execution flow, identify issues, and optimize performance.
However, improper logging can lead to inefficient debugging or performance overhead.

When to Use N/log

The N/log module is useful in scenarios such as: - Debugging SuiteScript logic by recording variable states and function calls. - Monitoring workflow executions for unexpected behaviors. - Capturing user actions in client scripts for validation. - Auditing system interactions in server scripts.

Common Logging Methods

NetSuite provides four primary logging methods:

import log from 'N/log';

log.debug({ title: 'Debug Log', details: 'Tracking script execution.' });
log.audit({ title: 'Audit Log', details: 'User interaction recorded.' });
log.error({ title: 'Error Log', details: 'An issue occurred in the script.' });
log.emergency({ title: 'Emergency Log', details: 'Critical failure detected!' });

You can declare in a more concise way(work for all four methods):

log.debug('Debug Log', 'Tracking script execution.');

When the object is pass to the log method as a parameter, it will be stringified and displayed in the log.

Purpose of Each Log Level

Below are just for reference, you can use them in your own way.
In most of NetSuite log viewer, you can filter the log by the log level.

For the script deployment instance, you can define the log level in the script deployment page to make it only log the log with the level you want. - Debug: Provides detailed script execution information (development stage, frequently used). - Audit: Records significant business events or user interactions. - Error: Captures failures that require attention. - Emergency: Flags system-critical issues that demand immediate action.

Where to Find Logs in NetSuite

Logs generated using N/log can be accessed in multiple locations:

  • Script Execution Log: Customization > Scripting > Script Execution Log
    This page may display last 10,000 logs.
    You can filter the log by script, log date, log level.
  • Script Deployment Page: Customization > Scripting > Script Deployments
    Check on the log of a specific script deployment instance.
  • Script Record Logs: Customization > Scripting > Scripts
    Check on the log of a specific script record, will contain all the logs of the script deployment instances by that script record.

Logging in Client Scripts

In the client script, you can use console methods for logging:

console.log('Debug message from client script');
console.error('Error message from client script');

Then you can use the developer tool in the browser to view the log you wrote in the client script.

Length Limitations of N/log

Sometimes you may need to log a large object or message, built-in logging methods have length limitations and may cut off long messages.
Instead of log to the log directly, you can store the log to a file or a custom record.
Let me share a snippet for storing the log to a file:

function writeContentToFile(content){
   let updatedFile = file.create({
       name: 'log_'+ Date.now(),
       fileType: file.Type.PLAINTEXT,
       contents: content,
       folder: 1234 // the folder id you want to store the log
   });
   let newFileId = updatedFile.save();
}

Remember to add the N/file module to the script file when you try to use this snippet, and only pass the content in a string format.(Like for an object, you can use JSON.stringify to convert it to a string)

Summary

The N/log module is a crucial tool for SuiteScript developers.
By understanding its functions, limitations, and best practices, you can effectively debug and monitor your scripts without impacting system performance.
Keeping logs structured and purposeful ensures efficient troubleshooting and better script management.

 

 

 

 

 

 


About Us

Concentrus is a leading provider of innovative cloud-based enterprise resource planning (ERP) solutions, including NetSuite. Our team of NetSuite experts offers a range of services, including NetSuite price analysis, NetSuite training, and NetSuite integration services.  

Our goal is to help businesses of all sizes maximize their investment in NetSuite by providing expert NetSuite cost optimization and implementation strategies. With years of experience as a NetSuite partner, our NetSuite administrators and NetSuite consultants are well equipped to help businesses of all sizes with their NetSuite consulting needs.  

Whether you're looking for a NetSuite consultant to help with your NetSuite implementation or you need ongoing NetSuite support, Concentrus is here to help. 

 

Read About Our Implementation Methodology

 

Want more NetSuite Tips and Tricks? Check out our Short & 'Suite videos

 

Tags: NetSuite, ERP, Reporting, NetSuite Partner, NetSuite How To's, Accounting, NetSuite Tips, SuiteScript, log, save to file, snippet

Subscribe to our blog!

Recent Posts

Posts by Topic

see all

Request a quote