info

inline fun info(cause: Throwable? = null, crossinline buildLog: LogBuilder.() -> String)(source)

Calls the given lambda to build a log message, and logs it at LogLevel.INFO, if enabled.

If the log was caused by an exception, you can attach it to the log with the optional cause parameter before the lambda.

In the scope of the buildLog lambda, you can call LogBuilder.field to add structured key-value data to the log.

Example

private val log = getLogger()

fun example(event: Event) {
log.info {
field("event", event)
"Processing event"
}
}

Note on line numbers

If you include file location information in your log encoder (such as enabling includeCallerData in logstash-logback-encoder), then the log will show an incorrect line number. This happens because Logger's methods are inline, to avoid allocating a function object for buildLog. Inline functions give incorrect line numbers, but we prioritize the performance gain in this case. File, class and method names will still be correct.

Parameters

cause

Optional cause exception. Pass this in parentheses before the lambda.

buildLog

Returns the message to log. Will only be called if the log level is enabled, so you don't pay for string concatenation if it's not logged.

The LogBuilder receiver lets you call field in the scope of the lambda, to add structured key-value data to the log.

We mark the lambda as crossinline, so you don't accidentally do a non-local return in it, which would drop the log.