All Downloads are FREE. Search and download functionalities are using the official Maven repository.

slog.macros.LoggerImpl.scala Maven / Gradle / Ivy

The newest version!
package slog.macros

import slog.{LevelLogBuilder, LogBuilder}

import scala.reflect.macros.blackbox

private[slog] object LoggerImpl {
  def infoImpl[F[_]](c: blackbox.Context): c.Expr[LevelLogBuilder[F]] = {
    impl[F](c)(c.universe.TermName("info"))
  }

  def debugImpl[F[_]](c: blackbox.Context): c.Expr[LevelLogBuilder[F]] = {
    impl[F](c)(c.universe.TermName("debug"))
  }

  def traceImpl[F[_]](c: blackbox.Context): c.Expr[LevelLogBuilder[F]] = {
    impl[F](c)(c.universe.TermName("trace"))
  }

  def warnImpl[F[_]](c: blackbox.Context): c.Expr[LevelLogBuilder[F]] = {
    impl[F](c)(c.universe.TermName("warn"))
  }

  def errorImpl[F[_]](c: blackbox.Context): c.Expr[LevelLogBuilder[F]] = {
    impl[F](c)(c.universe.TermName("error"))
  }

  private def impl[F[_]](
      c: blackbox.Context
  )(level: c.universe.TermName): c.Expr[LevelLogBuilder[F]] = {
    import c.universe._
    val file = Literal(Constant(c.enclosingPosition.source.path.toString))
    val line = Literal(Constant(c.enclosingPosition.line))
    val tree = q"${c.prefix}.underlying.$level($file, $line)"
    c.Expr(tree)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy