From 9d55310fa13ec01e5e1685bd39b86e90e375e6cb Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Mon, 20 Jan 2025 11:00:43 -0600 Subject: [PATCH] Minor update to LoggerSupport.log to lazily evaluate --- cats/shared/src/main/scala/scribe/LoggerWrapper.scala | 2 +- cats/shared/src/main/scala/scribe/ScribeImpl.scala | 2 +- core/shared/src/main/scala/scribe/Logger.scala | 2 +- core/shared/src/main/scala/scribe/LoggerSupport.scala | 2 +- core/shared/src/main/scala/scribe/package.scala | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cats/shared/src/main/scala/scribe/LoggerWrapper.scala b/cats/shared/src/main/scala/scribe/LoggerWrapper.scala index fa26837e6..e496b899f 100644 --- a/cats/shared/src/main/scala/scribe/LoggerWrapper.scala +++ b/cats/shared/src/main/scala/scribe/LoggerWrapper.scala @@ -6,7 +6,7 @@ import scribe.message.LoggableMessage import sourcecode.{FileName, Line, Name, Pkg} class LoggerWrapper[F[_]](val wrapped: Logger, val sync: Sync[F]) extends Scribe[F] { - override def log(record: LogRecord): F[Unit] = sync.delay(wrapped.log(record)) + override def log(record: => LogRecord): F[Unit] = sync.delay(wrapped.log(record)) override def log(level: Level, mdc: MDC, features: LogFeature*) (implicit pkg: Pkg, fileName: FileName, name: Name, line: Line): F[Unit] = diff --git a/cats/shared/src/main/scala/scribe/ScribeImpl.scala b/cats/shared/src/main/scala/scribe/ScribeImpl.scala index c5b59c81e..ec3c56841 100644 --- a/cats/shared/src/main/scala/scribe/ScribeImpl.scala +++ b/cats/shared/src/main/scala/scribe/ScribeImpl.scala @@ -6,7 +6,7 @@ import scribe.message.LoggableMessage import sourcecode.{FileName, Line, Name, Pkg} class ScribeImpl[F[_]](val sync: Sync[F]) extends AnyVal with Scribe[F] { - override def log(record: LogRecord): F[Unit] = sync.delay(Logger(record.className).log(record)) + override def log(record: => LogRecord): F[Unit] = sync.delay(Logger(record.className).log(record)) override def log(level: Level, mdc: MDC, features: LogFeature*) (implicit pkg: Pkg, fileName: FileName, name: Name, line: Line): F[Unit] = diff --git a/core/shared/src/main/scala/scribe/Logger.scala b/core/shared/src/main/scala/scribe/Logger.scala index a5feeb6cc..a7d3ff36d 100644 --- a/core/shared/src/main/scala/scribe/Logger.scala +++ b/core/shared/src/main/scala/scribe/Logger.scala @@ -115,7 +115,7 @@ case class Logger(parentId: Option[LoggerId] = Some(Logger.RootId), }) } - override final def log(record: LogRecord): Unit = { + override final def log(record: => LogRecord): Unit = { val r = if (data.nonEmpty) { record.copy(data = data ++ record.data) } else { diff --git a/core/shared/src/main/scala/scribe/LoggerSupport.scala b/core/shared/src/main/scala/scribe/LoggerSupport.scala index cff9b42e8..c5d2d2e2a 100644 --- a/core/shared/src/main/scala/scribe/LoggerSupport.scala +++ b/core/shared/src/main/scala/scribe/LoggerSupport.scala @@ -6,7 +6,7 @@ import scribe.message.LoggableMessage import scala.language.experimental.macros trait LoggerSupport[F] extends Any { - def log(record: LogRecord): F + def log(record: => LogRecord): F def log(level: Level, mdc: MDC, features: LogFeature*) (implicit pkg: sourcecode.Pkg, diff --git a/core/shared/src/main/scala/scribe/package.scala b/core/shared/src/main/scala/scribe/package.scala index 9e3a49dc1..e64aefda5 100644 --- a/core/shared/src/main/scala/scribe/package.scala +++ b/core/shared/src/main/scala/scribe/package.scala @@ -11,7 +11,7 @@ package object scribe extends LoggerSupport[Unit] { protected[scribe] var disposables = Set.empty[() => Unit] @inline - override final def log(record: LogRecord): Unit = Logger(record.className).log(record) + override final def log(record: => LogRecord): Unit = Logger(record.className).log(record) override def log(level: Level, mdc: MDC, features: LogFeature*) (implicit pkg: Pkg, fileName: FileName, name: Name, line: Line): Unit =