# 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](https://docs.servoy.com/reference/servoycore/dev-api/application/jslogbuilder) | [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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **message** the message to log; the format depends on the message factory.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **exception** The exception to log.

**Returns:** [JSLogBuilder](https://docs.servoy.com/reference/servoycore/dev-api/application/jslogbuilder) the LogBuilder.

**Sample**

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

***
