-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to the logging capabilities of DataWeave #47
Comments
What is the usage of |
@machaval the usage of the
The I created a small DataWeave code to illustrate this, in which I only want to log something when a string length is 5 or more: %dw 2.0
fun myLog(prefix: String = "", value: Any, logValue: Boolean): Any =
if (logValue == false) (log(prefix) then value) else log(prefix, value)
output application/json
---
if (sizeOf(payload.message) >= 5) myLog("String length >= 5", payload.message, true)
else payload.message In this example, "String length >= 5" will be logged without the actual value if It's easily doable in a Mule application using the Logger component that always pass the message without touching it while allowing to log its values, but a similar behaviour is not possible in DW without writing a custom function as in my example. |
Hi @GauthierPLM Thanks for the clarification. The Thanks for the feedback. |
Current state
Currently, the logging capabilities of DataWeave are pretty limited and do not leverage everything the Java platform has to offer. The
log
function is pretty simple: it accepts a value, and optionally a message to prepend to the value. There are no way to customise the log level or the category of the log.In a production context, this limit the use cases of the
log
function as log acts like aprintln()
more than like a real logging utility.Having no way to only log some text without printing the value is also an important feature missing from DataWeave
log
function.Proposal
To improve DataWeave logging capabilities, I would suggest either extending the
log
function, or offer a new logging module that would offer the following:log
function.value
parameter but not print it.This would result in the following new functions:
Logging::log(category: String = "", level: String = "INFO", prefix: String = "", value: T): T
Logging::error(category: String = "", prefix: String = "", value: T): T
Logging::warn(category: String = "", prefix: String = "", value: T): T
Logging::info(category: String = "", prefix: String = "", value: T): T
Logging::debug(category: String = "", prefix: String = "", value: T): T
Logging::trace(category: String = "", prefix: String = "", value: T): T
These methods would be doubled with another set allowing not to print the value passed while still returning it:
Logging::log(category: String = "", level: String = "INFO", prefix: String = "", value: T, logValue: Boolean): T
Logging::error(category: String = "", prefix: String = "", value: T, logValue: Boolean): T
Logging::warn(category: String = "", prefix: String = "", value: T, logValue: Boolean): T
Logging::info(category: String = "", prefix: String = "", value: T, logValue: Boolean): T
Logging::debug(category: String = "", prefix: String = "", value: T, logValue: Boolean): T
Logging::trace(category: String = "", prefix: String = "", value: T, logValue: Boolean): T
These methods signatures would be compatible with the existing log function, offering an easy transition while remaining coherent with the existing core library.
The text was updated successfully, but these errors were encountered: