Skip to content

Commit

Permalink
Deprecate implicit use of LoggerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Aug 23, 2022
1 parent 4f02ef3 commit d00181c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ trait LoggerFactoryGen[F[_]] {
}

private[log4cats] trait LoggerFactoryGenCompanion {
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def getLogger[F[_]](implicit lf: LoggerFactoryGen[F], name: LoggerName): lf.LoggerType =
lf.getLogger
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def getLoggerFromName[F[_]](name: String)(implicit lf: LoggerFactoryGen[F]): lf.LoggerType =
lf.getLoggerFromName(name)
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def getLoggerFromClass[F[_]](clazz: Class[_])(implicit lf: LoggerFactoryGen[F]): lf.LoggerType =
lf.getLoggerFromClass(clazz)
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def create[F[_]](implicit lf: LoggerFactoryGen[F], name: LoggerName): F[lf.LoggerType] =
lf.create
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def fromName[F[_]](name: String)(implicit lf: LoggerFactoryGen[F]): F[lf.LoggerType] =
lf.fromName(name)
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def fromClass[F[_]](clazz: Class[_])(implicit lf: LoggerFactoryGen[F]): F[lf.LoggerType] =
lf.fromClass(clazz)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.typelevel.log4cats
package slf4j

import cats.effect.kernel.Sync
import org.slf4j.{Logger => JLogger}

trait Slf4jFactory[F[_]] extends LoggerFactory[F] {
Expand All @@ -26,8 +27,23 @@ trait Slf4jFactory[F[_]] extends LoggerFactory[F] {
}

object Slf4jFactory extends LoggerFactoryGenCompanion {
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
def apply[F[_]: Slf4jFactory]: Slf4jFactory[F] = implicitly

def create[F[_]: Sync]: Slf4jFactory[F] = new Slf4jFactory[F] {
override def getLoggerFromName(name: String): SelfAwareStructuredLogger[F] =
Slf4jLogger.getLoggerFromName(name)

override def getLoggerFromSlf4j(logger: JLogger): SelfAwareStructuredLogger[F] =
Slf4jLogger.getLoggerFromSlf4j(logger)

override def fromName(name: String): F[SelfAwareStructuredLogger[F]] =
Slf4jLogger.fromName(name)

override def fromSlf4j(logger: JLogger): F[SelfAwareStructuredLogger[F]] =
Slf4jLogger.fromSlf4j(logger)
}

def getLoggerFromSlf4j[F[_]](logger: JLogger)(implicit
lf: Slf4jFactory[F]
): SelfAwareStructuredLogger[F] = lf.getLoggerFromSlf4j(logger)
Expand Down
16 changes: 3 additions & 13 deletions slf4j/src/main/scala/org/typelevel/log4cats/slf4j/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@
package org.typelevel.log4cats

import cats.effect.Sync
import org.slf4j.{Logger => JLogger}

package object slf4j {
implicit def loggerFactoryforSync[F[_]: Sync]: Slf4jFactory[F] = new Slf4jFactory[F] {
override def getLoggerFromName(name: String): SelfAwareStructuredLogger[F] =
Slf4jLogger.getLoggerFromName(name)

override def getLoggerFromSlf4j(logger: JLogger): SelfAwareStructuredLogger[F] =
Slf4jLogger.getLoggerFromSlf4j(logger)

override def fromName(name: String): F[SelfAwareStructuredLogger[F]] =
Slf4jLogger.fromName(name)

override def fromSlf4j(logger: JLogger): F[SelfAwareStructuredLogger[F]] =
Slf4jLogger.fromSlf4j(logger)
}
@deprecated("LoggerFactories should be passed explicitly, not implicitly", "2.5.0")
implicit def loggerFactoryforSync[F[_]](implicit F: Sync[F]): Slf4jFactory[F] =
Slf4jFactory.create(F)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Slf4jLoggerOuterClassMacroTest {

object LoggingBaseline {
val t = new Throwable
def logger[F[_]: Sync]: SelfAwareStructuredLogger[F] = Slf4jFactory.getLogger[F]
def logger[F[_]: Sync]: SelfAwareStructuredLogger[F] = Slf4jFactory.create[F].getLogger

val traceM = logger[IO].trace("")
val traceTM = logger[IO].trace(t)("")
Expand Down

0 comments on commit d00181c

Please sign in to comment.