typelevel / typelevel/log4cats

Proposal for `log4cats-sourcecode` module to provide information about the call site

Open
#525 3 comments 4 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 suggest adding a module for integration with sourcecode to add information about the call site to the context of a structured logger. Rather than introduce a new subtype of Logger, I think the simplest thing is to put the logging methods on an object. It might look something like this:

object SourceCodeLogger {
  def info[F[_]](ctx: Map[String, String])(msg: => String)(implicit logger: StructuredLogger, line: sourcecode.Line, file: sourcecode.File): F[Unit] =
    logger.info(ctx ++ Map("callsite" -> s"${file.value}:${line.value}"))(msg)
  /* ... */
}

Of course there's endless scope for bike shedding about exactly what information should be provided and in what format, so I don't know if this is over-opinionated to go in a library like log4cats?

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 reviewing the proposed log4cats-sourcecode module and the StructuredLogger API, then inspect the linked sourcecode integration. The scope is not settled: completion would require an agreed API and format for adding call-site information to structured-logger context.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.