@@ -178,8 +178,14 @@ internal constructor(
178178 *
179179 * The [LogBuilder] receiver lets you call [field][LogBuilder.field] in the scope of the lambda,
180180 * to add structured key-value data to the log.
181+ *
182+ * We mark the lambda as `crossinline`, so you don't accidentally do a non-local return in it,
183+ * which would drop the log.
181184 */
182- public inline fun info (cause : Throwable ? = null, buildLog : LogBuilder .() -> String ) {
185+ public inline fun info (
186+ cause : Throwable ? = null,
187+ crossinline buildLog : LogBuilder .() -> String ,
188+ ) {
183189 if (isInfoEnabled) {
184190 log(LogLevel .INFO , cause, buildLog)
185191 }
@@ -225,8 +231,14 @@ internal constructor(
225231 *
226232 * The [LogBuilder] receiver lets you call [field][LogBuilder.field] in the scope of the lambda,
227233 * to add structured key-value data to the log.
234+ *
235+ * We mark the lambda as `crossinline`, so you don't accidentally do a non-local return in it,
236+ * which would drop the log.
228237 */
229- public inline fun warn (cause : Throwable ? = null, buildLog : LogBuilder .() -> String ) {
238+ public inline fun warn (
239+ cause : Throwable ? = null,
240+ crossinline buildLog : LogBuilder .() -> String ,
241+ ) {
230242 if (isWarnEnabled) {
231243 log(LogLevel .WARN , cause, buildLog)
232244 }
@@ -272,8 +284,14 @@ internal constructor(
272284 *
273285 * The [LogBuilder] receiver lets you call [field][LogBuilder.field] in the scope of the lambda,
274286 * to add structured key-value data to the log.
287+ *
288+ * We mark the lambda as `crossinline`, so you don't accidentally do a non-local return in it,
289+ * which would drop the log.
275290 */
276- public inline fun error (cause : Throwable ? = null, buildLog : LogBuilder .() -> String ) {
291+ public inline fun error (
292+ cause : Throwable ? = null,
293+ crossinline buildLog : LogBuilder .() -> String ,
294+ ) {
277295 if (isErrorEnabled) {
278296 log(LogLevel .ERROR , cause, buildLog)
279297 }
@@ -315,8 +333,14 @@ internal constructor(
315333 *
316334 * The [LogBuilder] receiver lets you call [field][LogBuilder.field] in the scope of the lambda,
317335 * to add structured key-value data to the log.
336+ *
337+ * We mark the lambda as `crossinline`, so you don't accidentally do a non-local return in it,
338+ * which would drop the log.
318339 */
319- public inline fun debug (cause : Throwable ? = null, buildLog : LogBuilder .() -> String ) {
340+ public inline fun debug (
341+ cause : Throwable ? = null,
342+ crossinline buildLog : LogBuilder .() -> String ,
343+ ) {
320344 if (isDebugEnabled) {
321345 log(LogLevel .DEBUG , cause, buildLog)
322346 }
@@ -358,8 +382,14 @@ internal constructor(
358382 *
359383 * The [LogBuilder] receiver lets you call [field][LogBuilder.field] in the scope of the lambda,
360384 * to add structured key-value data to the log.
385+ *
386+ * We mark the lambda as `crossinline`, so you don't accidentally do a non-local return in it,
387+ * which would drop the log.
361388 */
362- public inline fun trace (cause : Throwable ? = null, buildLog : LogBuilder .() -> String ) {
389+ public inline fun trace (
390+ cause : Throwable ? = null,
391+ crossinline buildLog : LogBuilder .() -> String ,
392+ ) {
363393 if (isTraceEnabled) {
364394 log(LogLevel .TRACE , cause, buildLog)
365395 }
@@ -409,17 +439,36 @@ internal constructor(
409439 *
410440 * The [LogBuilder] receiver lets you call [field][LogBuilder.field] in the scope of the lambda,
411441 * to add structured key-value data to the log.
442+ *
443+ * We mark the lambda as `crossinline`, so you don't accidentally do a non-local return in it,
444+ * which would drop the log.
412445 */
413446 public inline fun at (
414447 level : LogLevel ,
415448 cause : Throwable ? = null,
416- buildLog : LogBuilder .() -> String
449+ crossinline buildLog : LogBuilder .() -> String ,
417450 ) {
418451 if (isEnabledFor(level)) {
419452 log(level, cause, buildLog)
420453 }
421454 }
422455
456+ @PublishedApi
457+ internal inline fun log (
458+ level : LogLevel ,
459+ cause : Throwable ? ,
460+ crossinline buildLog : LogBuilder .() -> String ,
461+ ) {
462+ val builder = LogBuilder (createLogEvent(level, cause, underlyingLogger))
463+ val message = builder.buildLog()
464+ if (cause != null ) {
465+ // Call this after buildLog(), so cause exception fields don't overwrite LogBuilder fields
466+ builder.addFieldsFromCauseException(cause)
467+ }
468+
469+ builder.logEvent.log(message, underlyingLogger)
470+ }
471+
423472 /* *
424473 * Returns true if [LogLevel.ERROR] is enabled for this logger.
425474 *
@@ -486,18 +535,6 @@ internal constructor(
486535 TRACE = { isTraceEnabled },
487536 )
488537 }
489-
490- @PublishedApi
491- internal inline fun log (level : LogLevel , cause : Throwable ? , buildLog : LogBuilder .() -> String ) {
492- val builder = LogBuilder (createLogEvent(level, cause, underlyingLogger))
493- val message = builder.buildLog()
494- if (cause != null ) {
495- // Call this after buildLog(), so cause exception fields don't overwrite LogBuilder fields
496- builder.addFieldsFromCauseException(cause)
497- }
498-
499- builder.logEvent.log(message, underlyingLogger)
500- }
501538}
502539
503540/* *
@@ -508,11 +545,11 @@ internal constructor(
508545internal expect interface PlatformLogger {
509546 fun getName (): String
510547
511- fun isInfoEnabled (): Boolean
548+ fun isErrorEnabled (): Boolean
512549
513550 fun isWarnEnabled (): Boolean
514551
515- fun isErrorEnabled (): Boolean
552+ fun isInfoEnabled (): Boolean
516553
517554 fun isDebugEnabled (): Boolean
518555
0 commit comments