From 5b90ea45d11f9d5f59fbe1f071c6e613b5c2ba03 Mon Sep 17 00:00:00 2001 From: Gavin Bisesi Date: Sun, 20 Sep 2020 09:24:58 -0400 Subject: [PATCH 1/2] Add a `LogLevel.fromString` method I have this in my codebase, figured it makes sense to push upstream. Do we want it to match the output of `show` at all? --- .../scala/org/typelevel/log4cats/extras/LogLevel.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala b/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala index d001c37f..c2db3b67 100644 --- a/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala +++ b/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala @@ -25,6 +25,15 @@ object LogLevel { case object Info extends LogLevel case object Debug extends LogLevel case object Trace extends LogLevel + + def fromString(s: String): Option[LogLevel] = s.toLowerCase match { + case "error" => Some(LogLevel.Error) + case "warn" => Some(LogLevel.Warn) + case "info" => Some(LogLevel.Info) + case "debug" => Some(LogLevel.Debug) + case "trace" => Some(LogLevel.Trace) + case _ => None + } implicit val logLevelShow: Show[LogLevel] = Show.show[LogLevel] { case Error => "LogLevel.Error" From 56fc3a1b2c529bfdda00cb25f2e3da2913e25c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lor=C3=A1nd=20Szak=C3=A1cs?= Date: Wed, 10 Feb 2021 23:36:36 +0200 Subject: [PATCH 2/2] Match the output of Show in LogLevel.fromString --- .../org/typelevel/log4cats/extras/LogLevel.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala b/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala index c2db3b67..fa9b2482 100644 --- a/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala +++ b/core/shared/src/main/scala/org/typelevel/log4cats/extras/LogLevel.scala @@ -25,14 +25,19 @@ object LogLevel { case object Info extends LogLevel case object Debug extends LogLevel case object Trace extends LogLevel - + def fromString(s: String): Option[LogLevel] = s.toLowerCase match { case "error" => Some(LogLevel.Error) - case "warn" => Some(LogLevel.Warn) - case "info" => Some(LogLevel.Info) + case "warn" => Some(LogLevel.Warn) + case "info" => Some(LogLevel.Info) case "debug" => Some(LogLevel.Debug) case "trace" => Some(LogLevel.Trace) - case _ => None + case "loglevel.error" => Some(LogLevel.Error) + case "loglevel.warn" => Some(LogLevel.Warn) + case "loglevel.info" => Some(LogLevel.Info) + case "loglevel.debug" => Some(LogLevel.Debug) + case "loglevel.trace" => Some(LogLevel.Trace) + case _ => None } implicit val logLevelShow: Show[LogLevel] = Show.show[LogLevel] {