Skip to content

Commit

Permalink
take advantage of the new Trace[F].attachError signature to attach at…
Browse files Browse the repository at this point in the history
…tributes to the exception event
  • Loading branch information
bpholt committed Jan 18, 2023
1 parent 66d18dc commit 5b8971f
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package object natchez {
override def fromName(name: String): F[SelfAwareStructuredLogger[F]] = getLoggerFromName(name).pure[F]
}

implicit def traceLogger[F[_] : Trace : Applicative]: StructuredLogger[F] = new TraceLogger[F]
implicit def traceLogger[F[_] : Trace]: StructuredLogger[F] = new TraceLogger[F]
}

package natchez {
Expand Down Expand Up @@ -59,10 +59,10 @@ package natchez {
}

private[TraceLogger] val mapContextToTraceValue: Map[String, String] => List[(String, TraceValue)] =
_.toList.nested.map(TraceValue.StringValue.apply).value
_.toList.nested.map(TraceableValue[String].toTraceValue).value
}

class TraceLogger[F[_] : Trace : Applicative] extends StructuredLogger[F] {
class TraceLogger[F[_] : Trace] extends StructuredLogger[F] {
private def log(logLevel: LogLevel,
ctx: Map[String, String],
maybeThrowable: Option[Throwable],
Expand All @@ -73,7 +73,7 @@ package natchez {
"severity_text" -> logLevelToSeverityText(logLevel) ::
mapContextToTraceValue(ctx)

Trace[F].log(attributes: _*) *> maybeThrowable.fold(().pure[F])(Trace[F].attachError)
maybeThrowable.fold(Trace[F].log(attributes: _*))(Trace[F].attachError(_, attributes: _*))
}

override def trace(ctx: Map[String, String])(msg: => String): F[Unit] = log(LogLevel.Trace, ctx, None, msg)
Expand Down

0 comments on commit 5b8971f

Please sign in to comment.