typelevel / typelevel/log4cats

Improvement proposal: Better Factory-support for regular (non-SelfAware, non-Structured) Logger

Open
#878 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
416
Forks
77
Avg merge
6h 25m
Merged PRs (30d)
3

Description

I noticed some libraries, e.g. http4s, use LoggerFactory as context bound a lot even though all they need is a factory for a Logger, not for a SelfAwareStructuredLogger.

This means users of such libraries are force to provide instances of SelfAwareStructuredLogger even though the extra methods of SelfAwareLogger and StructuredLogger are not used at all. That makes it unneccessarily hard to use other logging frameworks than those supported by log4cats directly.

I guess the reasons why libraries use LoggerFactory as context bound when they only need a factory for a simple Logger are:

  • LoggerFactoryGen (which would allow to return a Loggerinstead of a SelfAwareStructuredLogger) has a less inviting name than LoggerFactory
  • a bunch of convenience stuff that is defined for LoggerFactory (e.g. mapK and implicit conversion like optionTFactory, eitherTFactory, ...) is not defined for LoggerFactoryGen

The "less inviting name" part probably cannot be changed without breaking everyone's code, so my proposal is to address the other reason and provide as much of the convenience stuff that is available for LoggerFactory for LoggerFactoryGen as possible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing LoggerFactoryGen with the convenience operations already available on LoggerFactory, including mapK, optionTFactory, and eitherTFactory. Define which equivalents are needed for regular Logger factories and verify that the resulting API covers the stated use cases without requiring SelfAwareStructuredLogger instances.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.