# JSLogBuilder

## Overview

The `JSLogBuilder` class facilitates constructing and logging events with support for exceptions and parameterized messages. It integrates with the logging framework and is instantiated through `JSLogger` methods. The class supports adding exceptions to log events, including `Throwable` and JavaScript's `NativeError`. Developers can log messages with or without additional parameters, using flexible formatting. When handling `NativeError` objects, it extracts properties like name, message, and stack trace for inclusion in the log. Additionally, it provides functionality to log events without a message, making it suitable for error-only logging scenarios. The logging level is preserved as part of the instance for potential configuration or usage.

## Methods Summarized

| Type                                                                      | Name                                                 | Summary                                    |
| ------------------------------------------------------------------------- | ---------------------------------------------------- | ------------------------------------------ |
| void                                                                      | [log()](#log)                                        | Logs an event without adding a message.    |
| void                                                                      | [log(message, params)](#log-message-params)          | Logs a message with or without parameters. |
| [JSLogBuilder](/reference/servoycore/dev-api/application/jslogbuilder.md) | [withException(exception)](#withexception-exception) | Includes an exception in the log event.    |

## Methods Detailed

### log()

Logs an event without adding a message.\
This can be useful in combination with withException(e) if no message is required.

**Returns:** void

**Sample**

```js
var log = application.getLogger();
log.warn.withException(myException).log();
```

### log(message, params)

Logs a message with or without parameters.

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **message** the message to log; the format depends on the message factory.
* [Array](/reference/servoycore/dev-api/js-lib/array.md) **params** parameters to the message.

**Returns:** void

**Sample**

```js
var log = application.getLogger();
log.warn.log("some message {} {} {}", "with", "multiple", "arguments");
```

### withException(exception)

Includes an exception in the log event.

**Parameters**

* [Object](/reference/servoycore/dev-api/js-lib/object.md) **exception** The exception to log.

**Returns:** [JSLogBuilder](/reference/servoycore/dev-api/application/jslogbuilder.md) the LogBuilder.

**Sample**

```js
var log = application.getLogger();
log.warn.withException(myException).log("some message");
```

***


---

# 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://docs.servoy.com/reference/servoycore/dev-api/application/jslogbuilder.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.
