# 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**:

```javascript
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 ID
* **Example**:

```javascript
const transactionId = triton.startTransaction();
```

### resumeTransaction(transactionId)

* **Description**: Resumes a transaction using an existing transaction ID
* **Parameters**:
  * `transactionId`: `{string}` Existing transaction ID to resume
* **Example**:

```javascript
triton.resumeTransaction('existing-transaction-id');
```

### stopTransaction()

* **Description**: Stops the current transaction and auto-flush monitor, flushes remaining logs
* **Example**:

```javascript
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 chaining
* **Example**:

```javascript
triton.exception(new Error('Something went wrong'));
```

### error(type, area)

* **Description**: Creates an error level log
* **Parameters**:
  * `type`: `{string}` Log type from TYPE enum
  * `area`: `{string}` Log area from AREA enum
* **Returns**: `{TritonBuilder}` Builder instance for chaining
* **Example**:

```javascript
triton.error(TYPE.FRONTEND, AREA.COMMUNITY);
```

### warning(type, area)

* **Description**: Creates a warning level log
* **Parameters**:
  * `type`: `{string}` Log type from TYPE enum
  * `area`: `{string}` Log area from AREA enum
* **Returns**: `{TritonBuilder}` Builder instance for chaining
* **Example**:

```javascript
triton.warning(TYPE.FRONTEND, AREA.ACCOUNTS);
```

### debug(type, area)

* **Description**: Creates a debug level log
* **Parameters**:
  * `type`: `{string}` Log type from TYPE enum
  * `area`: `{string}` Log area from AREA enum
* **Returns**: `{TritonBuilder}` Builder instance for chaining
* **Example**:

```javascript
triton.debug(TYPE.FRONTEND, AREA.OPPORTUNITY_MANAGEMENT);
```

### info(type, area)

* **Description**: Creates an info level log
* **Parameters**:
  * `type`: `{string}` Log type from TYPE enum
  * `area`: `{string}` Log area from AREA enum
* **Returns**: `{TritonBuilder}` Builder instance for chaining
* **Example**:

```javascript
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**:

```javascript
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 instance
* **Example**:

```javascript
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 flushed
* **Example**:

```javascript
await triton.flush();
```

### log(builder)

* **Description**: Adds a log builder to the buffer
* **Parameters**:
  * `builder`: `{TritonBuilder}` Builder instance to log
* **Returns**: `{TritonBuilder}` The builder instance
* **Example**:

```javascript
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 flushed
* **Example**:

```javascript
await triton.logNow(builder.summary('Critical operation'));
```

## Enums

### AREA

```javascript
{
    ACCOUNTS: 'ACCOUNTS',
    COMMUNITY: 'COMMUNITY',
    LEAD_CONVERSION: 'LEAD_CONVERSION',
    OPPORTUNITY_MANAGEMENT: 'OPPORTUNITY_MANAGEMENT',
    REST_API: 'REST_API'
}
```

### CATEGORY

```javascript
{
    LWC: 'LWC',
    AURA: 'Aura',
    WARNING: 'Warning',
    DEBUG: 'Debug',
    EVENT: 'Event'
}
```

### LEVEL

```javascript
{
    ERROR: 'ERROR',
    WARNING: 'WARNING',
    INFO: 'INFO',
    DEBUG: 'DEBUG',
    FINE: 'FINE',
    FINER: 'FINER',
    FINEST: 'FINEST'
}
```

### TYPE

```javascript
{
    BACKEND: 'Backend',
    FRONTEND: 'Frontend'
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triton.pharos.ai/pharos-triton/methods-reference/lwc/triton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
