Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7862ea0
commit 643015c
Showing
10 changed files
with
114 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
project/secret | ||
|
||
# Created by https://www.gitignore.io/api/scala,java,python,sbt,emacs,linux,vim | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package nequi.zio.logger | ||
|
||
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package nequi.zio.logger | ||
|
||
import scalaz.Show | ||
import scalaz.zio.IO | ||
|
||
private[logger] trait Logging { | ||
def trace[A: Show](a: A)(implicit L: Logger): IO[Throwable, Unit] = L.trace(a) | ||
def debug[A: Show](a: A)(implicit L: Logger): IO[Throwable, Unit] = L.debug(a) | ||
def info[A: Show](a: A)(implicit L: Logger): IO[Throwable, Unit] = L.info(a) | ||
def warn[A: Show](a: A)(implicit L: Logger): IO[Throwable, Unit] = L.warn(a) | ||
def error[A: Show](a: A)(implicit L: Logger): IO[Throwable, Unit] = L.error(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package nequi.zio | ||
|
||
package object logger extends Logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package nequi.zio.logger | ||
|
||
import java.util.ArrayDeque | ||
|
||
import scalaz.Show | ||
import scalaz.zio.IO | ||
|
||
trait QueueLogger { | ||
sealed trait Level | ||
case object Trace extends Level | ||
case object Debug extends Level | ||
case object Info extends Level | ||
case object Warn extends Level | ||
case object Error extends Level | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package nequi.zio.logger | ||
|
||
import org.slf4j | ||
|
||
import scalaz.Show | ||
import scalaz.zio.IO | ||
|
||
trait Slf4jLogger { | ||
def clazz: sourcecode.FullName | ||
|
||
lazy val clazzName: String = clazz.value.stripSuffix(".clazz") | ||
|
||
implicit lazy val logger: Logger = new 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))) | ||
} | ||
} |