---
schema_version: "1"
id: 508cebd2e92537678134c07d5da2ab5d7c81d1ad80a9893085cff686089fd692
title: DataWeave Logging Configuration
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dataweave-logging-configuration.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dataweave-logging-configuration
source_site: docs.mulesoft.com
content_type: documentation
content_hash: db9c1d4cd0f37abe76e9e86bc6b5a51e097860cfb74fd03d71992ee9ab811e03
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# DataWeave Logging Configuration

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Get granular control over DataWeave logging to debug and monitor your data transformations with
precision.

Starting with DataWeave 2.10, you can configure logging to control the verbosity of log messages
using standard log levels: `Debug`, `Info`, `Warn`, and `Error`. You can filter log messages by
severity and scope, which makes it easier to troubleshoot and monitor your DataWeave code.

## Configuration Location

Define the logging configuration in a DataWeave language file named `log-config.dwl`. Place this
file in the classpath at the root level.

Use the `DataWeaveScriptingEngine` API to customize the name, location, and format of the
configuration file by either implementing the `LoggingConfigurationSourceProvider` interface or by
using the `DefaultLoggingConfigurationSourceProvider` helper class.

> [!NOTE] The `DataWeaveScriptingEngine` API is available only when running DataWeave outside of
> Mule runtime. If you’re using Mule runtime, configure logging only with the `log-config.dwl` file
> and, if needed, the `log4j2.xml` configuration file.

The DataWeave code in this example retrieves the logging configuration in JSON format from a custom
classpath location.

```java
DataWeaveScriptingEngine engine = new DataWeaveScriptingEngine();
engine.withLoggingConfigurationSourceProvider(
  new DefaultLoggingConfigurationSourceProvider("classpath://org/acme/my-log-config.json")
);
```

## Configuration Structure

The `log-config.dwl` file contains an array of objects. Each object defines a logging rule with
these properties:

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Property</th><th>Description</th><th>Required for Scope</th><th>Possible Values</th></tr></thead><tbody><tr><td><div><div><p><code>scope</code></p></div></div></td><td><div><div><p>Specifies the scope of the logging rule.</p></div></div></td><td><div><div><p>Always required</p></div></div></td><td><div><div><p><code>Runtime</code> (applies to all DataWeave executions), <code>Module</code> (applies to all code within a specific module), and <code>Function</code> (applies to a specific function within a module)</p></div></div></td></tr><tr><td><div><div><p><code>level</code></p></div></div></td><td><div><div><p>Specifies the log level.</p></div></div></td><td><div><div><p>Always required</p></div></div></td><td><div><div><p><code>Debug</code>, <code>Info</code>, <code>Warn</code>, and <code>Error</code></p></div></div></td></tr><tr><td><div><div><p><code>module</code></p></div></div></td><td><div><div><p>Specifies the name of the DataWeave module.</p></div></div></td><td><div><div><p>Optional but required for <code>Module</code> and <code>Function</code></p></div></div></td><td><div><div><p>Any valid DataWeave module name</p></div></div></td></tr><tr><td><div><div><p><code>function</code></p></div></div></td><td><div><div><p>Specifies the name of the DataWeave function within the specified module.</p></div></div></td><td><div><div><p>Optional but required for <code>Function</code></p></div></div></td><td><div><div><p>Any valid DataWeave function name</p></div></div></td></tr></tbody></table>

## Example: Configuring Log Levels

This configuration sets three logging rules. The first rule sets the default log level for the
entire runtime to `Warn`, so only `Warn` and `Error` messages are logged unless a more specific rule
overrides it. The second rule sets the log level for the module `MyModule` to `Info`, which
overrides the runtime level and logs `Info`, `Warn`, and `Error` messages for all functions in
`MyModule`. The third rule sets the log level for the function `test` in `MyModule` to `Debug`,
which overrides both the module and runtime levels and logs all messages for this function.

```json
[
  {
    "scope": "Runtime",
    "level": "Warn"
  },
  {
    "scope": "Module",
    "module": "MyModule",
    "level": "Info"
  },
  {
    "scope": "Function",
    "module": "MyModule",
    "function": "test",
    "level": "Debug"
  }
]
```

## DataWeave Logging Functions

The DataWeave Core library provides these functions for logging messages:

<table><colgroup><col> <col></colgroup><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p><code>logWith&lt;T&gt;(level: LogLevel, prefix: String, value: T): T</code></p></div></div></td><td><div><div><p>Base function that provides the most flexibility. It takes a log level, an optional prefix, and a value to log, and returns the value.</p></div></div></td></tr><tr><td><div><div><p><code>logDebug&lt;T&gt;(prefix: String = "", value: T): T</code></p></div></div></td><td><div><div><p>Logs a message with the <code>Debug</code> level.</p></div></div></td></tr><tr><td><div><div><p><code>logInfo&lt;T&gt;(prefix: String = "", value: T): T</code></p></div></div></td><td><div><div><p>Logs a message with the <code>Info</code> level.</p></div></div></td></tr><tr><td><div><div><p><code>logWarn&lt;T&gt;(prefix: String = "", value: T): T</code></p></div></div></td><td><div><div><p>Logs a message with the <code>Warn</code> level.</p></div></div></td></tr><tr><td><div><div><p><code>logError&lt;T&gt;(prefix: String = "", value: T): T</code></p></div></div></td><td><div><div><p>Logs a message with the <code>Error</code> level.</p></div></div></td></tr><tr><td><div><div><p><code>log&lt;T&gt;(prefix: String = "", value: T): T</code></p></div></div></td><td><div><div><p>Logs a message with the <code>Info</code> level (shorthand for <code>logInfo</code>).</p></div></div></td></tr></tbody></table>

## Considerations

- Place the `log-config.dwl` file in the classpath for the configuration to take effect.

- Log levels are hierarchical. `Error` is the highest level, followed by `Warn`, `Info`, and
  `Debug`.

- More specific rules (for example, function-level rules) override less specific ones (for example,
  runtime-level rules).

- Use the `prefix` parameter in log functions to add context to your log messages.

- In Mule runtime, the default logging level shows only `Warn` and `Error` messages.

  To enable more detailed messages (`Info` or `Debug`), add a custom logger entry to your
  `log4j2.xml` configuration file in the `$MULE_HOME/conf/` directory.

  To enable `Debug` logging for DataWeave messages, add a custom logger entry to your `log4j2.xml`
  configuration file:

  ```xml
  <AsyncLogger name="org.mule.weave.v2.model.service.DefaultLoggingService$" level="DEBUG"/>
  ```

## See Also

- [Core (dw::Core)](https://docs.mulesoft.com/dataweave/latest/dw-core)
