Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bplommer opened this issue Nov 18, 2021 · 3 comments

Comments

@bplommer
Copy link
Contributor

bplommer commented Nov 18, 2021

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?

@ChristopherDavenport
Copy link
Member

I think it could, although I'm not 100% on sourcecode as I havne't used it. I normally use

https://github.com/tpolecat/SourcePos

for this sort of thing, but can be convinced for sure.

@bplommer
Copy link
Contributor Author

sourcepos looks good! I like that it only needs a single parameter and has its own opinionated toString.

@darkfrog26
Copy link

Scribe uses sourcecode since 3.x and it works beautifully with scribe-cats.

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

No branches or pull requests

3 participants