Contact Us 1-800-596-4880

DataWeave Logging Configuration

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.

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.

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:

Property Description Required for Scope Possible Values

scope

Specifies the scope of the logging rule.

Always required

Runtime (applies to all DataWeave executions), Module (applies to all code within a specific module), and Function (applies to a specific function within a module)

level

Specifies the log level.

Always required

Debug, Info, Warn, and Error

module

Specifies the name of the DataWeave module.

Optional but required for Module and Function

Any valid DataWeave module name

function

Specifies the name of the DataWeave function within the specified module.

Optional but required for Function

Any valid DataWeave function name

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.

[
  {
    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:

Function Description

logWith<T>(level: LogLevel, prefix: String, value: T): T

Base function that provides the most flexibility. It takes a log level, an optional prefix, and a value to log, and returns the value.

logDebug<T>(prefix: String = "", value: T): T

Logs a message with the Debug level.

logInfo<T>(prefix: String = "", value: T): T

Logs a message with the Info level.

logWarn<T>(prefix: String = "", value: T): T

Logs a message with the Warn level.

logError<T>(prefix: String = "", value: T): T

Logs a message with the Error level.

log<T>(prefix: String = "", value: T): T

Logs a message with the Info level (shorthand for logInfo).

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:

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

See Also