Skip to content

Conversation

@Jay-Lokhande
Copy link

@Jay-Lokhande Jay-Lokhande commented Jun 18, 2025

This PR's objective is to create a SAM type interface in log4cats

Comment on lines 19 to 23
final case class KernelLogLevel(name: String, value: Double) {
def namePadded: String = KernelLogLevel.padded(this)

KernelLogLevel.add(this)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (structure): I'm sick right now, but we should get on a call towards the end of next week and go over bincompat.

Case classes are wonderful for applications, but we're going to tend to avoid them because they don't play nicely with bincompat.

Copy link
Member

Choose a reason for hiding this comment

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

agreed 💯

Comment on lines 39 to 48
final def logTrace(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Trace, record)
final def logDebug(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Debug, record)
final def logInfo(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Info, record)
final def logWarn(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Warn, record)
final def logError(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Error, record)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (naming): If we do end up needing these, we should simplify down the names

Suggested change
final def logTrace(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Trace, record)
final def logDebug(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Debug, record)
final def logInfo(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Info, record)
final def logWarn(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Warn, record)
final def logError(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Error, record)
final def trace(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Trace, record)
final def debug(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Debug, record)
final def info(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Info, record)
final def warn(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Warn, record)
final def error(record: Log.Builder => Log.Builder): F[Unit] =
log(KernelLogLevel.Error, record)

Copy link
Author

Choose a reason for hiding this comment

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

lets keep it until final change, I tried to change as suggested but its giving error due to duplicates

@iRevive iRevive mentioned this pull request Jun 20, 2025
15 tasks
@Jay-Lokhande
Copy link
Author

Thank you for all the suggestions, I will rework on it

// All of these should be no-ops and not throw
logger.info("This should not appear").void *>
logger.error("This should not appear").void *>
logger.warn("This should not appear").void *>
Copy link
Contributor

Choose a reason for hiding this comment

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

cleanup: logger.warn and friends already return F[Unit], so you don't need to add .void

import cats.effect.IO
import munit.CatsEffectSuite

class SamLoggerTest extends CatsEffectSuite {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: tests that require you to inspect the console to see if they pass or not aren't automated tests.

They can be useful when doing exploratory programming, but they shouldn't generally be committed to source.

test("SamStructuredLogger should handle context with multiple entries") {
var capturedLogs: List[(KernelLogLevel, Log.Builder[String] => Log.Builder[String])] = Nil

val testKernel = new LoggerKernel[IO, String] {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Instead of inlining this with a var, it'd be better to rework the existing test loggers to use LoggerKernel

@Jay-Lokhande
Copy link
Author

@morgen-peschke just a gentle reminder regarding the PR review whenever you get a chance. I understand things can get busy thank you for your time and help!

Comment on lines +57 to +70
// Removed implicit conversions for monad transformers from Logger - these were intentionally removed
ProblemFilters
.exclude[DirectMissingMethodProblem]("org.typelevel.log4cats.Logger.kleisliLogger"),
ProblemFilters
.exclude[DirectMissingMethodProblem]("org.typelevel.log4cats.Logger.eitherTLogger"),
ProblemFilters
.exclude[DirectMissingMethodProblem]("org.typelevel.log4cats.Logger.optionTLogger"),
// Removed implicit conversions for monad transformers from LoggerFactory - these were intentionally removed
ProblemFilters
.exclude[DirectMissingMethodProblem]("org.typelevel.log4cats.LoggerFactory.kleisliFactory"),
ProblemFilters
.exclude[DirectMissingMethodProblem]("org.typelevel.log4cats.LoggerFactory.eitherTFactory"),
ProblemFilters
.exclude[DirectMissingMethodProblem]("org.typelevel.log4cats.LoggerFactory.optionTFactory"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Intentionally removed or not, filtering them out doesn't fix the bin-compat issues, so we should restore these methods.

Comment on lines +71 to +81
// Added new kernel methods - these are new API additions
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.typelevel.log4cats.Logger.kernel"),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"org.typelevel.log4cats.extras.DeferredLogger.kernel"
),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"org.typelevel.log4cats.extras.DeferredSelfAwareStructuredLogger.kernel"
),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"org.typelevel.log4cats.extras.DeferredStructuredLogger.kernel"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bumping tlBaseVersion will tell MiMa that you're going to do a minor version bump, and these will go away.

ThisBuild / tlBaseVersion := "2.8"

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.

3 participants