Skip to content
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

Add strict evaluation option #738

Merged
merged 3 commits into from
Apr 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,83 @@ object NoOpLogger {
def impl[F[_]: Applicative] = impl_[F](evaluateArgs = false)

private[noop] def impl_[F[_]: Applicative](evaluateArgs: Boolean): SelfAwareStructuredLogger[F] =
new SelfAwareStructuredLogger[F] {
if (evaluateArgs) stricImpl else lazyImpl

val no: F[Boolean] = Applicative[F].pure(false)
def void(arg: => Any): F[Unit] = Applicative[F].pure {
if (evaluateArgs) {
val _ = arg
()
} else ()
}
@inline override def isTraceEnabled: F[Boolean] = no
@inline override def isDebugEnabled: F[Boolean] = no
@inline override def isInfoEnabled: F[Boolean] = no
@inline override def isWarnEnabled: F[Boolean] = no
@inline override def isErrorEnabled: F[Boolean] = no
@inline override def trace(t: Throwable)(msg: => String): F[Unit] = void(t)
@inline override def trace(msg: => String): F[Unit] = void(msg)
@inline override def trace(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def debug(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def debug(msg: => String): F[Unit] = void(msg)
@inline override def debug(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def info(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def info(msg: => String): F[Unit] = void(msg)
@inline override def info(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def warn(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def warn(msg: => String): F[Unit] = void(msg)
@inline override def warn(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def error(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def error(msg: => String): F[Unit] = void(msg)
@inline override def error(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def trace(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def debug(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def info(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def warn(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def error(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
private def lazyImpl[F[_]: Applicative] = new SelfAwareStructuredLogger[F] {

val no: F[Boolean] = Applicative[F].pure(false)
val unit: F[Unit] = Applicative[F].pure(())

@inline override def isTraceEnabled: F[Boolean] = no
@inline override def isDebugEnabled: F[Boolean] = no
@inline override def isInfoEnabled: F[Boolean] = no
@inline override def isWarnEnabled: F[Boolean] = no
@inline override def isErrorEnabled: F[Boolean] = no
@inline override def trace(t: Throwable)(msg: => String): F[Unit] = unit
@inline override def trace(msg: => String): F[Unit] = unit
@inline override def trace(ctx: Map[String, String])(msg: => String): F[Unit] = unit
@inline override def debug(t: Throwable)(msg: => String): F[Unit] = unit
@inline override def debug(msg: => String): F[Unit] = unit
@inline override def debug(ctx: Map[String, String])(msg: => String): F[Unit] = unit
@inline override def info(t: Throwable)(msg: => String): F[Unit] = unit
@inline override def info(msg: => String): F[Unit] = unit
@inline override def info(ctx: Map[String, String])(msg: => String): F[Unit] = unit
@inline override def warn(t: Throwable)(msg: => String): F[Unit] = unit
@inline override def warn(msg: => String): F[Unit] = unit
@inline override def warn(ctx: Map[String, String])(msg: => String): F[Unit] = unit
@inline override def error(t: Throwable)(msg: => String): F[Unit] = unit
@inline override def error(msg: => String): F[Unit] = unit
@inline override def error(ctx: Map[String, String])(msg: => String): F[Unit] = unit
@inline override def trace(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
unit
@inline override def debug(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
unit
@inline override def info(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
unit
@inline override def warn(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
unit
@inline override def error(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
unit
}

private def stricImpl[F[_]: Applicative] = new SelfAwareStructuredLogger[F] {
ant8e marked this conversation as resolved.
Show resolved Hide resolved

val no: F[Boolean] = Applicative[F].pure(false)
def void(arg: => Any): F[Unit] = Applicative[F].pure {
val _ = arg
()
}

@inline override def isTraceEnabled: F[Boolean] = no
@inline override def isDebugEnabled: F[Boolean] = no
@inline override def isInfoEnabled: F[Boolean] = no
@inline override def isWarnEnabled: F[Boolean] = no
@inline override def isErrorEnabled: F[Boolean] = no
ant8e marked this conversation as resolved.
Show resolved Hide resolved
@inline override def trace(t: Throwable)(msg: => String): F[Unit] = void(t)
@inline override def trace(msg: => String): F[Unit] = void(msg)
@inline override def trace(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def debug(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def debug(msg: => String): F[Unit] = void(msg)
@inline override def debug(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def info(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def info(msg: => String): F[Unit] = void(msg)
@inline override def info(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def warn(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def warn(msg: => String): F[Unit] = void(msg)
@inline override def warn(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def error(t: Throwable)(msg: => String): F[Unit] = void(msg)
@inline override def error(msg: => String): F[Unit] = void(msg)
@inline override def error(ctx: Map[String, String])(msg: => String): F[Unit] = void(msg)
@inline override def trace(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def debug(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def info(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def warn(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
@inline override def error(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] =
void(msg)
}

}