Triton
Overview
The Triton
class provides a singleton implementation for logging in Lightning Web Components (LWC) and Aura components. It manages log buffering, transaction context, and component-specific templates.
Constructor
Triton()
Description: Creates or returns the singleton instance of the Triton logger
Returns: Triton instance
Example:
const triton = new Triton();
Transaction Methods
startTransaction()
Description: Generates and stores a new transaction ID and starts the auto-flush monitor
Returns:
{string}
The generated transaction IDExample:
const transactionId = triton.startTransaction();
resumeTransaction(transactionId)
Description: Resumes a transaction using an existing transaction ID
Parameters:
transactionId
:{string}
Existing transaction ID to resume
Example:
triton.resumeTransaction('existing-transaction-id');
stopTransaction()
Description: Stops the current transaction and auto-flush monitor, flushes remaining logs
Example:
triton.stopTransaction();
Logging Methods
exception(error)
Description: Creates an error log from a JavaScript Error object
Parameters:
error
:{Error}
JavaScript Error object to log
Returns:
{TritonBuilder}
Builder instance for chainingExample:
triton.exception(new Error('Something went wrong'));
error(type, area)
Description: Creates an error level log
Parameters:
type
:{string}
Log type from TYPE enumarea
:{string}
Log area from AREA enum
Returns:
{TritonBuilder}
Builder instance for chainingExample:
triton.error(TYPE.FRONTEND, AREA.COMMUNITY);
warning(type, area)
Description: Creates a warning level log
Parameters:
type
:{string}
Log type from TYPE enumarea
:{string}
Log area from AREA enum
Returns:
{TritonBuilder}
Builder instance for chainingExample:
triton.warning(TYPE.FRONTEND, AREA.ACCOUNTS);
debug(type, area)
Description: Creates a debug level log
Parameters:
type
:{string}
Log type from TYPE enumarea
:{string}
Log area from AREA enum
Returns:
{TritonBuilder}
Builder instance for chainingExample:
triton.debug(TYPE.FRONTEND, AREA.OPPORTUNITY_MANAGEMENT);
info(type, area)
Description: Creates an info level log
Parameters:
type
:{string}
Log type from TYPE enumarea
:{string}
Log area from AREA enum
Returns:
{TritonBuilder}
Builder instance for chainingExample:
triton.info(TYPE.FRONTEND, AREA.REST_API);
Template Methods
setTemplate(builder)
Description: Sets a builder template that can be re-used for the calling component
Parameters:
builder
:{TritonBuilder}
Builder to be used as template
Example:
triton.setTemplate(builder.type(TYPE.FRONTEND).area(AREA.COMMUNITY));
fromTemplate()
Description: Creates a new builder from the saved template for the calling component
Returns:
{TritonBuilder}
New builder instanceExample:
const builder = triton.fromTemplate().summary('New log entry');
Buffer Management
flush()
Description: Sends all buffered logs to the server and clears the buffer
Returns:
{Promise}
Promise that resolves when logs are flushedExample:
await triton.flush();
log(builder)
Description: Adds a log builder to the buffer
Parameters:
builder
:{TritonBuilder}
Builder instance to log
Returns:
{TritonBuilder}
The builder instanceExample:
triton.log(builder.summary('Operation completed'));
logNow(builder)
Description: Immediately flushes a single log builder
Parameters:
builder
:{TritonBuilder}
Builder instance to log
Returns:
{Promise}
Promise that resolves when the log is flushedExample:
await triton.logNow(builder.summary('Critical operation'));
Enums
AREA
{
ACCOUNTS: 'ACCOUNTS',
COMMUNITY: 'COMMUNITY',
LEAD_CONVERSION: 'LEAD_CONVERSION',
OPPORTUNITY_MANAGEMENT: 'OPPORTUNITY_MANAGEMENT',
REST_API: 'REST_API'
}
CATEGORY
{
LWC: 'LWC',
AURA: 'Aura',
WARNING: 'Warning',
DEBUG: 'Debug',
EVENT: 'Event'
}
LEVEL
{
ERROR: 'ERROR',
WARNING: 'WARNING',
INFO: 'INFO',
DEBUG: 'DEBUG',
FINE: 'FINE',
FINER: 'FINER',
FINEST: 'FINEST'
}
TYPE
{
BACKEND: 'Backend',
FRONTEND: 'Frontend'
}
Last updated