> For the complete documentation index, see [llms.txt](https://docs.servoy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.servoy.com/reference/servoycore/dev-api/application/jslogbuilder.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/application/jslogbuilder.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
