Skip to content

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

@bplommer

Description

@bplommer

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions