From cda7e6177bab134cfa90776aa8089bd927bc97ff Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Sat, 11 Dec 2021 05:02:00 +0100 Subject: [PATCH 1/7] Update sbt-scalajs, scalajs-compiler, ... to 1.8.0 in series/1.x --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index cee818a4..713ab5b6 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.5") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0") addSbtPlugin("com.47deg" % "sbt-microsites" % "1.3.4") addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3") From 5cdfe596ac0ab0dd1d58c6ad42897c5d25fb29d7 Mon Sep 17 00:00:00 2001 From: danicheg Date: Tue, 28 Dec 2021 20:53:50 +0300 Subject: [PATCH 2/7] Add syntax for the Logger --- .../typelevel/log4cats/syntax/package.scala | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 core/shared/src/main/scala/org/typelevel/log4cats/syntax/package.scala diff --git a/core/shared/src/main/scala/org/typelevel/log4cats/syntax/package.scala b/core/shared/src/main/scala/org/typelevel/log4cats/syntax/package.scala new file mode 100644 index 00000000..4b2746f6 --- /dev/null +++ b/core/shared/src/main/scala/org/typelevel/log4cats/syntax/package.scala @@ -0,0 +1,36 @@ +/* + * Copyright 2018 Christopher Davenport + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.typelevel.log4cats + +package object syntax { + implicit final class LoggerInterpolator(private val sc: StringContext) extends AnyVal { + def error[F[_]](message: Any*)(implicit logger: Logger[F]): F[Unit] = + logger.error(sc.s(message: _*)) + + def warn[F[_]](message: Any*)(implicit logger: Logger[F]): F[Unit] = + logger.warn(sc.s(message: _*)) + + def info[F[_]](message: Any*)(implicit logger: Logger[F]): F[Unit] = + logger.info(sc.s(message: _*)) + + def debug[F[_]](message: Any*)(implicit logger: Logger[F]): F[Unit] = + logger.debug(sc.s(message: _*)) + + def trace[F[_]](message: Any*)(implicit logger: Logger[F]): F[Unit] = + logger.trace(sc.s(message: _*)) + } +} From 51a33dd0ba83210d0b8eb60fe20e0e966b400eb4 Mon Sep 17 00:00:00 2001 From: danicheg Date: Tue, 28 Dec 2021 21:27:33 +0300 Subject: [PATCH 3/7] Update microsite docs --- docs/src/main/mdoc/index.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/src/main/mdoc/index.md b/docs/src/main/mdoc/index.md index 440c86d8..2b947f03 100644 --- a/docs/src/main/mdoc/index.md +++ b/docs/src/main/mdoc/index.md @@ -59,3 +59,24 @@ def passForEasierUse[F[_]: Sync: Logger] = for { _ <- Logger[F].info("Logging at end of passForEasierUse") } yield something ``` + +### Laconic syntax +It's possible to use interpolated syntax for logging. +Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. +You can use it for your custom `Logger` as well as for Slf4j `Logger`. + +```scala mdoc +import cats.effect.Sync +import org.typelevel.log4cats.Logger +import org.typelevel.log4cats.syntax._ + +def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1) +def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!")) + +def log[F[_]: Sync: Logger] = + for { + result1 <- successComputation[F] + _ <- info"First result is $result1" + _ <- errorComputation[F].onError(_ => error"We got an error!") + } yield () +``` \ No newline at end of file From bb189fd05d583f915f440b90d76ff05975be06f2 Mon Sep 17 00:00:00 2001 From: danicheg Date: Tue, 28 Dec 2021 21:28:44 +0300 Subject: [PATCH 4/7] Update README --- README.md | 22 ++++++++++++++++++++++ docs/src/main/mdoc/index.md | 1 + 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 6fa684b9..991b00dc 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,25 @@ object MyThing { } yield something } ``` + +### Laconic syntax + +It's possible to use interpolated syntax for logging. +Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. +You can use it for your custom `Logger` as well as for Slf4j `Logger`. + +```scala mdoc +import cats.effect.Sync +import org.typelevel.log4cats.Logger +import org.typelevel.log4cats.syntax._ + +def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1) +def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!")) + +def log[F[_]: Sync: Logger] = + for { + result1 <- successComputation[F] + _ <- info"First result is $result1" + _ <- errorComputation[F].onError(_ => error"We got an error!") + } yield () +``` diff --git a/docs/src/main/mdoc/index.md b/docs/src/main/mdoc/index.md index 2b947f03..f99ffdbe 100644 --- a/docs/src/main/mdoc/index.md +++ b/docs/src/main/mdoc/index.md @@ -61,6 +61,7 @@ def passForEasierUse[F[_]: Sync: Logger] = for { ``` ### Laconic syntax + It's possible to use interpolated syntax for logging. Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. You can use it for your custom `Logger` as well as for Slf4j `Logger`. From cb870a05e88a8e25a0097f992aa36aef7e93662b Mon Sep 17 00:00:00 2001 From: danicheg Date: Tue, 28 Dec 2021 21:31:31 +0300 Subject: [PATCH 5/7] Fix warning in docs --- docs/src/main/mdoc/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/main/mdoc/index.md b/docs/src/main/mdoc/index.md index f99ffdbe..f5c36a67 100644 --- a/docs/src/main/mdoc/index.md +++ b/docs/src/main/mdoc/index.md @@ -27,7 +27,7 @@ libraryDependencies ++= Seq( ```scala mdoc import org.typelevel.log4cats.Logger import org.typelevel.log4cats.slf4j.Slf4jLogger -import cats.effect.{Sync, IO} +import cats.effect.Sync import cats.implicits._ object MyThing { From 4673c281dec753c046e6ad33576079bc74b921af Mon Sep 17 00:00:00 2001 From: danicheg Date: Tue, 28 Dec 2021 21:55:43 +0300 Subject: [PATCH 6/7] Make a more meaty example of the syntax --- README.md | 5 +++-- docs/src/main/mdoc/index.md | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 991b00dc..e23e9773 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,13 @@ It's possible to use interpolated syntax for logging. Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. You can use it for your custom `Logger` as well as for Slf4j `Logger`. -```scala mdoc +```scala +import cats.Applicative import cats.effect.Sync import org.typelevel.log4cats.Logger import org.typelevel.log4cats.syntax._ -def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1) +def successComputation[F[_]: Applicative]: F[Int] = Applicative[F].pure(1) def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!")) def log[F[_]: Sync: Logger] = diff --git a/docs/src/main/mdoc/index.md b/docs/src/main/mdoc/index.md index f5c36a67..9a6c1827 100644 --- a/docs/src/main/mdoc/index.md +++ b/docs/src/main/mdoc/index.md @@ -67,17 +67,20 @@ Currently, supported ops are: `trace`, `debug`, `info`, `warn`, `error`. You can use it for your custom `Logger` as well as for Slf4j `Logger`. ```scala mdoc +import cats.Applicative import cats.effect.Sync import org.typelevel.log4cats.Logger import org.typelevel.log4cats.syntax._ -def successComputation[F[_]: Sync]: F[Int] = Sync[F].pure(1) +def successComputation[F[_]: Applicative]: F[Int] = Applicative[F].pure(1) def errorComputation[F[_]: Sync]: F[Unit] = Sync[F].raiseError[Unit](new Throwable("Sorry!")) def log[F[_]: Sync: Logger] = for { result1 <- successComputation[F] _ <- info"First result is $result1" - _ <- errorComputation[F].onError(_ => error"We got an error!") + _ <- errorComputation[F].onError { + case _ => error"We got an error!" + } } yield () ``` \ No newline at end of file From 2412008de781dff93bf494f567ce011a485b1dd3 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Fri, 31 Dec 2021 04:34:31 +0100 Subject: [PATCH 7/7] Update sbt-scalajs, scalajs-compiler, ... to 1.8.0 in series/1.x --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 4d64be55..4455dd39 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,5 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0") addSbtPlugin("com.47deg" % "sbt-microsites" % "1.3.4") addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")