Skip to content

Commit d2c3d64

Browse files
committed
Revert "The Companion trait did not work as expected"
This reverts commit 7167e54.
1 parent 7167e54 commit d2c3d64

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,39 @@ package org.typelevel.log4cats
1818

1919
import scala.annotation.implicitNotFound
2020

21-
@implicitNotFound("""Implicit not found for LoggerFactory[${F}].
22-
Information can be found here: https://log4cats.github.io/logging-capability.html
23-
""")
21+
@implicitNotFound("""|
22+
|Implicit not found for LoggerFactory[${F}].
23+
|
24+
|Information can be found here: https://log4cats.github.io/logging-capability.html
25+
|""")
2426
trait LoggerFactory[F[_]] extends LoggerFactoryGen[F, SelfAwareStructuredLogger[F]]
27+
object LoggerFactory extends LoggerFactoryCompanion
28+
29+
private[log4cats] trait LoggerFactoryCompanion {
30+
def getLogger[F[_]](implicit
31+
lf: LoggerFactory[F],
32+
name: LoggerName
33+
): SelfAwareStructuredLogger[F] =
34+
lf.getLogger
35+
def getLoggerFromName[F[_]](name: String)(implicit
36+
lf: LoggerFactory[F]
37+
): SelfAwareStructuredLogger[F] =
38+
lf.getLoggerFromName(name)
39+
40+
def getLoggerFromClass[F[_]](clazz: Class[_])(implicit
41+
lf: LoggerFactory[F]
42+
): SelfAwareStructuredLogger[F] =
43+
lf.getLoggerFromClass(clazz)
44+
45+
def create[F[_]](implicit
46+
lf: LoggerFactory[F],
47+
name: LoggerName
48+
): F[SelfAwareStructuredLogger[F]] =
49+
lf.create
50+
def fromName[F[_]](name: String)(implicit lf: LoggerFactory[F]): F[SelfAwareStructuredLogger[F]] =
51+
lf.fromName(name)
52+
def fromClass[F[_]](clazz: Class[_])(implicit
53+
lf: LoggerFactory[F]
54+
): F[SelfAwareStructuredLogger[F]] =
55+
lf.fromClass(clazz)
56+
}

slf4j/src/main/scala/org/typelevel/log4cats/slf4j/Slf4jFactory.scala

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.typelevel.log4cats
18-
package slf4j
17+
package org.typelevel.log4cats.slf4j
1918

2019
import cats.effect.Sync
20+
import org.typelevel.log4cats.{LoggerFactory, LoggerFactoryCompanion, SelfAwareStructuredLogger}
2121
import org.slf4j.{Logger => JLogger}
2222

2323
trait Slf4jFactory[F[_]] extends LoggerFactory[F] {
@@ -26,7 +26,7 @@ trait Slf4jFactory[F[_]] extends LoggerFactory[F] {
2626
def fromSlf4j(logger: JLogger): F[SelfAwareStructuredLogger[F]]
2727
}
2828

29-
object Slf4jFactory {
29+
object Slf4jFactory extends LoggerFactoryCompanion {
3030
def apply[F[_]: Slf4jFactory]: Slf4jFactory[F] = implicitly
3131

3232
implicit def forSync[F[_]: Sync]: Slf4jFactory[F] = new Slf4jFactory[F] {
@@ -51,31 +51,4 @@ object Slf4jFactory {
5151
lf: Slf4jFactory[F]
5252
): F[SelfAwareStructuredLogger[F]] =
5353
lf.fromSlf4j(logger)
54-
55-
def getLogger[F[_]](implicit
56-
lf: Slf4jFactory[F],
57-
name: LoggerName
58-
): SelfAwareStructuredLogger[F] =
59-
lf.getLogger
60-
def getLoggerFromName[F[_]](name: String)(implicit
61-
lf: Slf4jFactory[F]
62-
): SelfAwareStructuredLogger[F] =
63-
lf.getLoggerFromName(name)
64-
65-
def getLoggerFromClass[F[_]](clazz: Class[_])(implicit
66-
lf: Slf4jFactory[F]
67-
): SelfAwareStructuredLogger[F] =
68-
lf.getLoggerFromClass(clazz)
69-
70-
def create[F[_]](implicit
71-
lf: Slf4jFactory[F],
72-
name: LoggerName
73-
): F[SelfAwareStructuredLogger[F]] =
74-
lf.create
75-
def fromName[F[_]](name: String)(implicit lf: Slf4jFactory[F]): F[SelfAwareStructuredLogger[F]] =
76-
lf.fromName(name)
77-
def fromClass[F[_]](clazz: Class[_])(implicit
78-
lf: Slf4jFactory[F]
79-
): F[SelfAwareStructuredLogger[F]] =
80-
lf.fromClass(clazz)
8154
}

slf4j/src/test/scala/org/typelevel/log4cats/slf4j/Slf4jLoggerMacroCompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Slf4jLoggerOuterClassMacroTest {
4848

4949
object LoggingBaseline {
5050
val t = new Throwable
51-
def logger[F[_]: Sync]: SelfAwareStructuredLogger[F] = Slf4jFactory.getLogger[F]
51+
def logger[F[_]: Sync]: SelfAwareStructuredLogger[F] = Slf4jLogger.getLogger[F]
5252

5353
val traceM = logger[IO].trace("")
5454
val traceTM = logger[IO].trace(t)("")

0 commit comments

Comments
 (0)