Skip to content

Conversation

@igor-ramazanov
Copy link

@igor-ramazanov igor-ramazanov commented Feb 22, 2025

Direct log4cats integration without slf4j middleman.
Allows using Woof with the new http4s-1.x as it requires LoggerFactory[F] for EmberClientBuilder and EmberServerBuilder.

Works on JVM.

On JS test needs to be fixed - the LogInfo is a little wonky there.

Couldn't run Native locally, apparently it hangs on linking.

Failed to run mdoc too.

@igor-ramazanov igor-ramazanov marked this pull request as ready for review February 22, 2025 13:34
@igor-ramazanov igor-ramazanov changed the title Add log4cats integration Add direct log4cats integration Feb 22, 2025
val callingMethodIndex = stacktraceElements.size - lastIndex
val callingMethod = stacktraceElements(callingMethodIndex)
val fileName =
(callingMethod.getClassName.replace('.', '/') + ".scala").split("\\/").takeRight(1).mkString
Copy link
Author

@igor-ramazanov igor-ramazanov Feb 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On JS it returns something like (<jscode>.scala:96229), not sure how to get a source file / line number.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log4cats doesn't support sourcecode info, but it's a requirement for woof.

Perhaps, I could create a variant of Logger#doLog which doesn't require LogInfo to facilitate log4cats integration.

Comment on lines 46 to 50
override def isErrorEnabled: F[Boolean] = Applicative[F].pure(true)
override def isWarnEnabled: F[Boolean] = Applicative[F].pure(true)
override def isInfoEnabled: F[Boolean] = Applicative[F].pure(true)
override def isDebugEnabled: F[Boolean] = Applicative[F].pure(true)
override def isTraceEnabled: F[Boolean] = Applicative[F].pure(true)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's a problem, but log level filtering works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have something similar in the slf4j-module:

private def testLevel(logLevel: LogLevel): Boolean = true
def isDebugEnabled(): Boolean = testLevel(LogLevel.Debug)
def isErrorEnabled(): Boolean = testLevel(LogLevel.Error)
def isInfoEnabled(): Boolean = testLevel(LogLevel.Info)
def isTraceEnabled(): Boolean = testLevel(LogLevel.Trace)
def isWarnEnabled(): Boolean = testLevel(LogLevel.Warn)

it should probably be reflected as a limitation in the docs

@hejfelix
Copy link
Collaborator

Sorry, I missed this one in the scala steward noise. I'll give it a look next week when I'm back to work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants