diff --git a/build.sbt b/build.sbt index 9df3be1..65c4be9 100644 --- a/build.sbt +++ b/build.sbt @@ -21,7 +21,7 @@ libraryDependencies ++= Seq( "com.lihaoyi" %% "sourcecode" % "0.1.5", "com.lihaoyi" %% "utest" % "0.6.6" % Test, "org.scalaz" %% "scalaz-core" % "7.2.27", - "org.scalaz" %% "scalaz-zio" % "0.6.3", + "org.scalaz" %% "scalaz-zio" % "1.0-RC4", "org.slf4j" % "slf4j-api" % "1.7.26", compilerPlugin("com.github.ghik" %% "silencer-plugin" % "1.3.2"), "com.github.ghik" %% "silencer-lib" % "1.3.2" % Provided diff --git a/src/main/scala/console.scala b/src/main/scala/console.scala deleted file mode 100644 index 92ae091..0000000 --- a/src/main/scala/console.scala +++ /dev/null @@ -1,17 +0,0 @@ -package nequi.zio.logger - -import scalaz.Show -import scalaz.zio.{ console, IO } - -trait ConsoleLogger { - implicit lazy val logger: Logger = new Logger { - private def log[A](level: String)(a: A)(implicit S: Show[A]): IO[Throwable, Unit] = - console.putStrLn(s"[${level}] ${S.shows(a)}") - - def trace[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = log("TRACE")(a) - def debug[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = log("DEBUG")(a) - def info[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = log("INFO")(a) - def warn[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = log("WARN")(a) - def error[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = log("ERROR")(a) - } -} diff --git a/src/main/scala/logger.scala b/src/main/scala/logger.scala index 40bd411..97b6176 100644 --- a/src/main/scala/logger.scala +++ b/src/main/scala/logger.scala @@ -4,9 +4,9 @@ import scalaz.Show import scalaz.zio.IO trait Logger { - def trace[A: Show](a: A): IO[Throwable, Unit] - def debug[A: Show](a: A): IO[Throwable, Unit] - def info[A: Show](a: A): IO[Throwable, Unit] - def warn[A: Show](a: A): IO[Throwable, Unit] - def error[A: Show](a: A): IO[Throwable, Unit] + def trace[A: Show](a: A): IO[Nothing, Unit] + def debug[A: Show](a: A): IO[Nothing, Unit] + def info[A: Show](a: A): IO[Nothing, Unit] + def warn[A: Show](a: A): IO[Nothing, Unit] + def error[A: Show](a: A): IO[Nothing, Unit] } diff --git a/src/main/scala/queue.scala b/src/main/scala/queue.scala index 94a0eb1..01749cd 100644 --- a/src/main/scala/queue.scala +++ b/src/main/scala/queue.scala @@ -16,13 +16,13 @@ trait QueueLogger { val queue = new ArrayDeque[(Level, String)] implicit lazy val logger: Logger = new Logger { - def trace[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = - IO.syncThrowable(queue.offer((Trace, S.shows(a)))).void - def debug[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = - IO.syncThrowable(queue.offer((Debug, S.shows(a)))).void - def info[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(queue.offer((Info, S.shows(a)))).void - def warn[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(queue.offer((Warn, S.shows(a)))).void - def error[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = - IO.syncThrowable(queue.offer((Error, S.shows(a)))).void + def trace[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = + IO.effectTotal(queue.offer((Trace, S.shows(a)))).unit + def debug[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = + IO.effectTotal(queue.offer((Debug, S.shows(a)))).unit + def info[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(queue.offer((Info, S.shows(a)))).unit + def warn[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(queue.offer((Warn, S.shows(a)))).unit + def error[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = + IO.effectTotal(queue.offer((Error, S.shows(a)))).unit } } diff --git a/src/main/scala/slf4j.scala b/src/main/scala/slf4j.scala index 0db8fc3..ea193a1 100644 --- a/src/main/scala/slf4j.scala +++ b/src/main/scala/slf4j.scala @@ -17,10 +17,10 @@ trait Slf4jLogger { implicit lazy val logger: Logger with InnerLogger[slf4j.Logger] = new Logger with InnerLogger[slf4j.Logger] { val inner: slf4j.Logger = slf4j.LoggerFactory.getLogger(clazzName) - def trace[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(inner.trace(S.shows(a))) - def debug[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(inner.debug(S.shows(a))) - def info[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(inner.info(S.shows(a))) - def warn[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(inner.warn(S.shows(a))) - def error[A](a: A)(implicit S: Show[A]): IO[Throwable, Unit] = IO.syncThrowable(inner.error(S.shows(a))) + def trace[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(inner.trace(S.shows(a))) + def debug[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(inner.debug(S.shows(a))) + def info[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(inner.info(S.shows(a))) + def warn[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(inner.warn(S.shows(a))) + def error[A](a: A)(implicit S: Show[A]): IO[Nothing, Unit] = IO.effectTotal(inner.error(S.shows(a))) } }