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.

·4 min read·View Oracle Docs

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.log for 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 TypeNameReturn TypeSupported Script TypesDescription
Methodlog.audit(options)voidClient and server scriptsLogs an Audit message.
Methodlog.debug(options)voidClient and server scriptsLogs a Debug message.
Methodlog.emergency(options)voidClient and server scriptsLogs an Emergency message.
Methodlog.error(options)voidClient and server scriptsLogs an Error message.

Example of Using N/log

Here’s a script example demonstrating logging:

suitescript
1/**
2 * @NApiVersion 2.x
3 * @NScriptType UserEventScript
4 */
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: myObject
18 });
19
20 log.debug({
21 title: 'Debug Entry',
22 details: 'Value of myValue is: ' + myValue
23 });
24
25 log.emergency({
26 title: 'Emergency Entry',
27 details: 'Value of myValue is: ' + myValue
28 });
29
30 log.error({
31 title: 'Error Entry',
32 details: 'Value of myValue is: ' + myValue
33 });
34 }
35 return {
36 beforeLoad: beforeLoad
37 };
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.log for 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?
Yes, the N/log module can be used in both client and server scripts to log execution details.
What are the limitations on logging with the N/log module in NetSuite?
NetSuite limits logging to 100,000 log method calls every 60 minutes across all scripts in a company, and logs older than 30 days are purged from the system.
How should logging be handled for client scripts attached to forms?
For client scripts attached to forms, log messages will be ignored by the N/log module. It's recommended to use `console.log` for such scripts.
What happens to log messages if the log storage limit is reached?
Each customer has a log storage limit of 5 million entries. Once this limit is reached, message persistence is not guaranteed unless custom records are used for longer retention.
Source: N/log Module Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →