A working example in README.md
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 58/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- scala
- Domain
- documentation
Research direction
Start with the example in README.md and try compiling it as written to identify the required corrections. Make the example executable and ensure its logging patterns, including the unsafeLogger discussion at (A), are clear and valid; done means a newcomer can follow the README example without manual modifications.
Written by the indexing model from the issue text.
Description
The example I copied from README.md cannot be compiled correctly without modifications. I also suggest making it executable. I find it helpful to someone like me who is unfamiliar with this style of logging.
While we are at it, is the unsafeLogger defined at (A) considered impure? Thanks
import io.chrisdavenport.log4cats.Logger
import io.chrisdavenport.log4cats.slf4j.Slf4jLogger
import cats.effect.{ExitCode, IO, IOApp, Sync}
import cats.implicits._
object MyThing extends IOApp {
// Arbitrary Local Function Declaration
def doSomething[F[_]: Sync]: F[Unit] = {
// Impure But What 90% of Folks I know do with log4s
implicit def unsafeLogger[F[_]: Sync] = Slf4jLogger.getLogger[F]
Logger[F].info("Logging Start Something") *>
Sync[F].delay(println("I could be doing anything")).attempt.flatMap {
case Left(e) => Logger[F].error(e)("Something Went Wrong")
case Right(_) => Sync[F].pure(())
}
}
def safelyDoThings[F[_]: Sync]: F[Unit] =
for {
logger <- Slf4jLogger.create[F]
_ <- logger.info("Logging at start of safelyDoThings")
something <- Sync[F]
.delay(println("I could do anything"))
.onError { case e => logger.error(e)("Something Went Wrong in safelyDoThings") }
_ <- logger.info("Logging at end of safelyDoThings")
} yield something
def passForEasierUse[F[_]: Sync: Logger] =
for {
_ <- Logger[F].info("Logging at start of passForEasierUse")
something <- Sync[F]
.delay(println("I could do anything"))
.onError { case e => Logger[F].error(e)("Something Went Wrong in passForEasierUse") }
_ <- Logger[F].info("Logging at end of passForEasierUse")
} yield something
override def run(args: List[String]): IO[ExitCode] =
doSomething[IO] *>
MyThing.safelyDoThings[IO] *> {
// Impure But What 90% of Folks I know do with log4s
implicit def unsafeLogger[F[_]: Sync] = Slf4jLogger.getLogger[F] // (A)
MyThing.passForEasierUse[IO]
} *>
IO(ExitCode.Success)
}
- Dominant language
- Scala
- Stars
- 416
- Forks
- 77
- Avg merge
- 6h 25m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from typelevel/log4cats
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Improvement proposal: Better Factory-support for regular (non-SelfAware, non-Structured) Logger Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
All issues in typelevel/log4cats
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ergoplatform/ergodocs#614 ·
-
area:ci enhancement requires-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion-comet#6078 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
[VL] madvise(WILLNEED) call fails in MmapFileStream because of wrong calculation of fetching length Openbug triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
chipsalliance/rocket-chip#3831 ·