Log Levels in SuiteScript for Effective Debugging

Understand log levels in SuiteScript to filter execution messages and enhance debugging practices.

·3 min read·View Oracle Docs

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 LevelDescriptionExample Uses
DebugShows all messages, suitable for testing.Use during development; avoid in production to reduce noise.
AuditRecords events during script processing."A request was made to an external site."
ErrorLogs unexpected script errors.Critical errors that need attention during execution.
EmergencyLogs 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 Debug logging for development environments to avoid cluttering logs in production.
  • Audit for Monitoring: Use the Audit level 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:

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 var myObject = { name: 'Jane', id: '123' };
10
11 log.audit({
12 title: 'Audit Entry',
13 details: myObject
14 });
15
16 log.debug({
17 title: 'Debug Entry',
18 details: 'Value of myValue is: ' + myValue
19 });
20
21 log.emergency({
22 title: 'Emergency Entry',
23 details: 'Critical condition for: ' + myValue
24 });
25
26 log.error({
27 title: 'Error Entry',
28 details: 'Error processing value: ' + myValue
29 });
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?
The available log levels in SuiteScript are Debug, Audit, Error, and Emergency.
How do log levels in SuiteScript affect script execution logs?
Log levels act as a filter for script execution logs, where only messages of the selected level or higher are logged. For example, setting the log level to Error logs only `log.error` and `log.emergency` messages.
What is the best practice for using the Debug log level in SuiteScript?
The Debug log level should be used sparingly and reserved for development environments, as it can clutter logs and affect performance in production environments.
How can I access and filter SuiteScript execution logs in NetSuite?
You can access and filter execution logs by navigating to _Customization > Scripting > Script Execution Logs_ and filtering logs by execution date, log level, and script name.
Source: Using Log Levels 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 SuiteScript

View all SuiteScript articles →