Skip to content

Commit 79483b9

Browse files
committed
fixup! fixup! Add logger with Local semantics
docs
1 parent 6eeb3d7 commit 79483b9

File tree

2 files changed

+58
-18
lines changed

2 files changed

+58
-18
lines changed

core/shared/src/main/scala/org/typelevel/log4cats/LocalLogger.scala

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@ import cats.mtl.{LiftKind, Local}
2020
import cats.syntax.flatMap.*
2121
import cats.{~>, Monad, Show}
2222

23+
/**
24+
* A logger with [[cats.mtl.Local `Local`]] semantics.
25+
*
26+
* @see
27+
* [[withAddedContext]]
28+
*/
2329
sealed trait LocalLogger[F[_]] extends SelfAwareLogger[F] {
2430

2531
/**
26-
* @return
27-
* the given effect modified to have the provided context stored [[cats.mtl.Local locally]]
32+
* Modifies the given effect to have the provided context stored [[cats.mtl.Local locally]].
33+
*
34+
* Context added using this method is available to all loggers created by this logger's
35+
* [[LocalLoggerFactory parent factory]].
2836
*/
2937
def withAddedContext[A](ctx: Map[String, String])(fa: F[A]): F[A]
3038

3139
/**
32-
* @return
33-
* the given effect modified to have the provided context stored [[cats.mtl.Local locally]]
40+
* Modifies the given effect to have the provided context stored [[cats.mtl.Local locally]].
41+
*
42+
* Context added using this method is available to all loggers created by this logger's
43+
* [[LocalLoggerFactory parent factory]].
3444
*/
3545
def withAddedContext[A](ctx: (String, Show.Shown)*)(fa: F[A]): F[A]
3646

@@ -45,20 +55,24 @@ sealed trait LocalLogger[F[_]] extends SelfAwareLogger[F] {
4555
def trace(ctx: Map[String, String])(msg: => String): F[Unit]
4656
def trace(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit]
4757

48-
@deprecated(
49-
"use the overload that takes a `LiftKind` and `Monad` instead",
50-
since = "2.8.0"
51-
)
58+
@deprecated("use `liftTo` instead", since = "log4cats 2.8.0")
5259
override def mapK[G[_]](fk: F ~> G): SelfAwareLogger[G] = super.mapK(fk)
5360

5461
/** Lifts this logger's context from `F` to `G`. */
5562
def liftTo[G[_]](implicit lift: LiftKind[F, G], G: Monad[G]): LocalLogger[G]
5663

5764
override def withModifiedString(f: String => String): LocalLogger[F]
5865

66+
/**
67+
* A view of this logger as a [[`StructuredLogger`]], to support gradual migration away from
68+
* `StructuredLogger`. Log context added using this `LocalLogger` or its
69+
* [[LocalLoggerFactory parent factory]] will be included in log messages created by
70+
* `StructuredLogger`s returned by this method, regardless of the scope in which this method was
71+
* called.
72+
*/
5973
@deprecated(
6074
"`StructuredLogger` is cumbersome and lacks `cats.mtl.Local` semantics",
61-
since = "2.8.0"
75+
since = "log4cats 2.8.0"
6276
)
6377
def asStructuredLogger: SelfAwareStructuredLogger[F]
6478
}
@@ -86,10 +100,7 @@ object LocalLogger {
86100
def isDebugEnabled: F[Boolean] = underlying.isDebugEnabled
87101
def isTraceEnabled: F[Boolean] = underlying.isTraceEnabled
88102

89-
@deprecated(
90-
"use the overload that takes a `LiftKind` and `Monad` instead",
91-
since = "2.8.0"
92-
)
103+
@deprecated("use `liftTo` instead", since = "log4cats 2.8.0")
93104
override def mapK[G[_]](fk: F ~> G): SelfAwareStructuredLogger[G] =
94105
super.mapK(fk)
95106
def liftTo[G[_]](implicit lift: LiftKind[F, G], G: Monad[G]): LocalLogger[G] =
@@ -99,7 +110,7 @@ object LocalLogger {
99110

100111
@deprecated(
101112
"`StructuredLogger` is cumbersome and lacks `cats.mtl.Local` semantics",
102-
since = "2.8.0"
113+
since = "log4cats 2.8.0"
103114
)
104115
def asStructuredLogger: SelfAwareStructuredLogger[F] = this
105116

@@ -229,12 +240,28 @@ object LocalLogger {
229240
)
230241
}
231242

243+
/**
244+
* This method should only be used when a [[`LoggerFactory`]] is not available; when possible,
245+
* create a [[`LocalLoggerFactory`]] and use that to create `LocalLogger`s.
246+
*
247+
* @return
248+
* a [[cats.mtl.Local local]] logger backed by the given [[`LocalLogContext`]] and
249+
* [[`LoggerFactory`]]
250+
*/
232251
def apply[F[_]: Monad](
233252
localLogContext: LocalLogContext[F],
234253
underlying: SelfAwareStructuredLogger[F]
235254
): LocalLogger[F] =
236255
new Impl(localLogContext, underlying)
237256

257+
/**
258+
* This method should only be used when a [[`LoggerFactory`]] is not available; when possible,
259+
* create a [[`LocalLoggerFactory`]] and use that to create `LocalLogger`s.
260+
*
261+
* @return
262+
* a local logger backed by the given [[`SelfAwareStructuredLogger`]] and implicit
263+
* [[cats.mtl.Local `Local`]]
264+
*/
238265
def fromLocal[F[_]: Monad](
239266
underlying: SelfAwareStructuredLogger[F]
240267
)(implicit localCtx: Local[F, Map[String, String]]): LocalLogger[F] =

core/shared/src/main/scala/org/typelevel/log4cats/LocalLoggerFactory.scala

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ import cats.mtl.{LiftKind, Local}
2020
import cats.syntax.functor.*
2121
import cats.{Functor, Monad, Show}
2222

23+
/** A factory for [[LocalLogger loggers]] with [[cats.mtl.Local `Local`]] semantics. */
2324
sealed trait LocalLoggerFactory[F[_]] extends LoggerFactoryGen[F] {
2425
final type LoggerType = LocalLogger[F]
2526

2627
/**
27-
* @return
28-
* the given effect modified to have the provided context stored [[cats.mtl.Local locally]]
28+
* Modifies the given effect to have the provided context stored [[cats.mtl.Local locally]].
29+
*
30+
* Context added using this method is available to all loggers created by this factory.
2931
*/
3032
def withAddedContext[A](ctx: Map[String, String])(fa: F[A]): F[A]
3133

3234
/**
33-
* @return
34-
* the given effect modified to have the provided context stored [[cats.mtl.Local locally]]
35+
* Modifies the given effect to have the provided context stored [[cats.mtl.Local locally]].
36+
*
37+
* Context added using this method is available to all loggers created by this factory.
3538
*/
3639
def withAddedContext[A](ctx: (String, Show.Shown)*)(fa: F[A]): F[A]
3740

@@ -62,12 +65,22 @@ object LocalLoggerFactory {
6265
underlying.fromName(name).map(LocalLogger(localLogContext, _))
6366
}
6467

68+
/**
69+
* @return
70+
* a factory for [[cats.mtl.Local local]] loggers backed by the given [[`LocalLogContext`]] and
71+
* [[`LoggerFactory`]]
72+
*/
6573
def apply[F[_]: Monad](
6674
localLogContext: LocalLogContext[F],
6775
underlying: LoggerFactory[F]
6876
): LocalLoggerFactory[F] =
6977
new Impl(localLogContext, underlying)
7078

79+
/**
80+
* @return
81+
* a factory for local loggers backed by the given [[`LoggerFactory`]] and implicit
82+
* [[cats.mtl.Local `Local`]]
83+
*/
7184
def fromLocal[F[_]: Monad](
7285
underlying: LoggerFactory[F]
7386
)(implicit localCtx: Local[F, Map[String, String]]): LocalLoggerFactory[F] =

0 commit comments

Comments
 (0)