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

Macro based location aware logging. #877

Merged
merged 5 commits into from
Jan 27, 2022
Merged

Macro based location aware logging. #877

merged 5 commits into from
Jan 27, 2022

Conversation

FunFunFine
Copy link
Member

This PR adds Location data type and a special version of tofu.syntax.logging called tofu.syntax.location.logging which is aware of the location where the call was made.

Basically, it allows one to have one global logger (while ignoring SLF4J location) and use it like that:

package my.cool.service

import cats.effect.IO
import tofu.syntax.location.logging._

class MyService(myDeps: Deps) {
  implicit val logger = Logs.plain[IO].forService[MyService]
  
  def doSomething(arg: Arg): IO[Result] = 
   for {
    _ <- trace"Gonna do stuff"
    result <- myDeps.foo(arg)
   _ <- info"Done stuff and got $result"
   } yield ()
}

Location will be put as an additional LoggedValue and will look something like that:

my.cool.service.MyService.doSomething@(MyService.scala:10)

Main goal of this PR is to discuss and add Location and macro for it. All other improvements (such as integration with SLF4J and global logger) should be done later.

@Odomontois Odomontois merged commit a7fa5d5 into master Jan 27, 2022
@mergify mergify bot deleted the location-logging branch January 27, 2022 16:36
@vilunov vilunov added the enhancement New feature or request label Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants