Skip to content

Commit

Permalink
Minor update to LoggerSupport.log to lazily evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Jan 20, 2025
1 parent 8980bd0 commit 9d55310
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cats/shared/src/main/scala/scribe/LoggerWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion cats/shared/src/main/scala/scribe/ScribeImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/scribe/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/scribe/LoggerSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/scribe/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 9d55310

Please # to comment.