> For the complete documentation index, see [llms.txt](https://docs.eximee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/logowanie-w-scriptcode.md).

# Logging in ScriptCode

## Available logging methods

In the ScriptCode environment, the object **`Logger`**, which allows logging events and data from the script.

{% hint style="info" %}
All arguments passed to methods `Logger.<method>()` are treated by default as **sensitive data**, i.e. potentially containing sensitive data, and will be hidden in nonsensitive logs.
{% endhint %}

Available logging methods:

```javascript
function callService(context) {
    Logger.info('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
    Logger.debug('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
    Logger.warn('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
    Logger.error('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
    Logger.trace('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
}
```

### Choosing the logging level

In ScriptCode, primarily use the level `INFO`. The most important errors and exceptions are logged automatically by the platform mechanisms.

<table data-header-hidden><thead><tr><th width="186.873291015625"></th><th></th></tr></thead><tbody><tr><td>Level</td><td>Principle of use in ScriptCode</td></tr><tr><td><code>INFO</code></td><td><strong>Default logging level.</strong> Use for diagnostic and business information needed to trace the script's execution.</td></tr><tr><td><code>WARN</code></td><td><strong>Use only in justified cases.</strong> Intended for significant and unusual situations requiring analysis.</td></tr><tr><td><code>ERROR</code></td><td><strong>Do not use in ScriptCode.</strong> Errors requiring logging at the level <code>ERROR</code> are handled and logged by the platform.</td></tr><tr><td><code>DEBUG</code>, <code>TRACE</code></td><td>Use for detailed diagnostics during development. These logs are not available in test and production environments.</td></tr></tbody></table>

<details>

<summary>INFO - default logging level</summary>

Use the level `INFO` to log information needed to analyze the script flow, e.g. execution of an important business step or taking a specific logic path.

```javascript
Logger.info(
    'Application status sent successfully [status={}]',
    nonsensitive(status)
);
```

You can use `Logger.info()`, when an additional entry really helps diagnostics. However, remember not to duplicate data logged automatically by the platform and not to add excessive information.

</details>

<details>

<summary>WARN - used only in justified cases</summary>

Level `WARN` use only for significant and unusual situations that should be noticed and analyzed.

Entries `WARN` are visible in production environments and are subject to analysis, so do not use this level as the default way of logging errors in the script.

If the situation is a standard part of business logic or the entry serves only to diagnose the script's operation, use `INFO`.

> If you are not sure whether the situation requires using `WARN`, use `INFO`.

</details>

<details>

<summary>ERROR - do not use in ScriptCode</summary>

Entries `ERROR` indicate serious system operation errors and can cause an alarm situation and a notification to the support line in the production environment.

Errors requiring logging at the level `ERROR` are handled and logged by the platform mechanisms.

</details>

### Business exceptions

In ScriptCode, trigger business errors using platform mechanisms: [Business errors](/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/formularze/tworzenie-formularza/strony-bledow.md#bledy-biznesowe).

If the script throws a business exception, the platform automatically logs its occurrence at the level `WARN`. Do not additionally log the same event with `Logger.warn()` nor `Logger.error()`.

### Logging in try/catch blocks

In `try/catch` use primarily the level `INFO`.

Use the level `WARN` use only when the caught situation is significant and unusual enough to require later analysis.

***

## Data logged by default

Platform **Eximee** automatically logs and treats as **sensitive** the following elements of the ScriptCode environment:

* data **input** forms (`input`),
* data **output** (`output`),
* content **requests** (`request`) sent to external services, e.g. via REST API,
* content **responses** (`response`) received from those services.

This data is not printed in nonsensitive logs in a way that allows its actual content to be read. It is replaced with the markers `_SENSITIVE_DATA_START_ ... _SENSITIVE_DATA_STOP_` or `#hashed#`, depending on the application type and execution context.

***

## Sensitive and nonsensitive logging

If we want some of the data to be printed in nonsensitive logs **without masking**, we need to use the method **`nonsensitive()`**, which marks the passed argument as nonsensitive.

Example:

```javascript
Logger.info(
    'COMPLETE TASK EXECUTED [arg1={}, arg2={}]',
    nonsensitive('arg1 nonsensitive test'),
    'arg2'
);
```

In this example:

* `arg1` will be written to the log in plain form,
* `arg2` will be hidden (replaced with a sensitive data marker).

> Use `nonsensitive()` only when you are sure that the passed value does not contain sensitive data. If you are unsure, leave the value as sensitive.

***

## Log format

Examples of log formats for different Eximee platform applications are shown below.

#### Application `process-handlers`

```
2023-07-20 11:52:07.130 CEST [pb=csadas21312das][pi=149e3ba0-26e3-11ee-8889-927e393a9856][pd=script_code_handler_test_process][sn=process-handler-complete-task][pt=eximeeScriptCodeTask][sci=a919bbb6-1dea-4044-a5ca-ee5f2f0c55ad][TopicSubscriptionManager] INFO  c.c.r.e.l.JavascriptLibraryLoader - Loading javascript libraries from directory=_SENSITIVE_DATA_START_._SENSITIVE_DATA_STOP_

2023-07-20 11:52:07.162 CEST [pb=csadas21312das][pi=149e3ba0-26e3-11ee-8889-927e393a9856][pd=script_code_handler_test_process][sn=process-handler-complete-task][pt=eximeeScriptCodeTask][sci=a919bbb6-1dea-4044-a5ca-ee5f2f0c55ad][TopicSubscriptionManager] INFO  c.c.e.s.logging.JavaScriptLoggerImpl - COMPLETE TASK EXECUTED [arg1=arg1 nonsensitive test, arg2=_SENSITIVE_DATA_START_arg2_SENSITIVE_DATA_STOP_]

2023-07-20 11:52:07.163 CEST [pb=csadas21312das][pi=149e3ba0-26e3-11ee-8889-927e393a9856][pd=script_code_handler_test_process][sn=process-handler-complete-task][pt=eximeeScriptCodeTask][sci=a919bbb6-1dea-4044-a5ca-ee5f2f0c55ad][TopicSubscriptionManager] WARN  c.c.e.s.logging.JavaScriptLoggerImpl - COMPLETE TASK EXECUTED [arg1=_SENSITIVE_DATA_START_arg1_SENSITIVE_DATA_STOP_, arg2=_SENSITIVE_DATA_START_arg2_SENSITIVE_DATA_STOP_]

2023-07-20 11:52:07.163 CEST [pb=csadas21312das][pi=149e3ba0-26e3-11ee-8889-927e393a9856][pd=script_code_handler_test_process][sn=process-handler-complete-task][pt=eximeeScriptCodeTask][sci=a919bbb6-1dea-4044-a5ca-ee5f2f0c55ad][TopicSubscriptionManager] ERROR c.c.e.s.logging.JavaScriptLoggerImpl - COMPLETE TASK EXECUTED [arg1=_SENSITIVE_DATA_START_arg1_SENSITIVE_DATA_STOP_, arg2=_SENSITIVE_DATA_START_arg2_SENSITIVE_DATA_STOP_]
```

***

#### Application `webforms`

```
2023-07-20 16:15:27,489 CEST [MK_1611202307201615273] [] [http-nio-8082-exec-36] INFO  c.c.e.s.l.l.JavaScriptLoggerImpl - COMPLETE TASK EXECUTED [arg1=arg1 nonsensitive test, arg2=#hashed#]

2023-07-20 16:15:27,490 CEST [MK_1611202307201615273] [] [http-nio-8082-exec-36] WARN  c.c.e.s.l.l.JavaScriptLoggerImpl - COMPLETE TASK EXECUTED [arg1=#hashed#, arg2=#hashed#]

2023-07-20 16:15:27,490 CEST [MK_1611202307201615273] [] [http-nio-8082-exec-36] ERROR c.c.e.s.l.l.JavaScriptLoggerImpl - COMPLETE TASK EXECUTED [arg1=#hashed#, arg2=#hashed#]
```

***

## Best practices

* For logging in ScriptCode, use only the object `Logger`.
* By default, use the level `INFO`.
* Use the level `WARN` use very rarely and only for significant, unusual situations requiring analysis.
* Do not use `Logger.error()` - errors at the level `ERROR` are logged by the platform.
* Do not log input, output, request, or response data again if the platform is already logging them.
* Do not log business exceptions again.
* Use `nonsensitive()` only for data that you are sure is not sensitive.
* Avoid logging entire objects, large data structures, and information that is not needed for diagnostics.


---

# 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 dynamically by asking a question.

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

```
GET https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/logowanie-w-scriptcode.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
