-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1896 from sideeffffect/log4cats
Add module for log4cats support for debugging purposes
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 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
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
54 changes: 54 additions & 0 deletions
54
modules/log4cats/src/main/scala/doobie/log4cats/Log4CatsDebuggingLogHandler.scala
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,54 @@ | ||
// Copyright (c) 2013-2020 Rob Norris and Contributors | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package doobie.log4cats | ||
|
||
import doobie.LogHandler | ||
import doobie.util.log._ | ||
import org.typelevel.log4cats._ | ||
|
||
/** | ||
* A LogHandler that writes a default format to a log4cats MessageLogger. | ||
* This is provided for debugging purposes and is not intended for production use, because it could log sensitive data. | ||
* | ||
* @group Constructors | ||
*/ | ||
class Log4CatsDebuggingLogHandler[F[_]](logger: MessageLogger[F]) extends LogHandler[F]{ | ||
override def run(logEvent: LogEvent): F[Unit] = logEvent match { | ||
case Success(s, a, l, e1, e2) => | ||
logger.info( | ||
s"""Successful Statement Execution: | ||
| | ||
| ${s.linesIterator.dropWhile(_.trim.isEmpty).mkString("\n ")} | ||
| | ||
| arguments = [${a.mkString(", ")}] | ||
| label = $l | ||
| elapsed = ${e1.toMillis.toString} ms exec + ${e2.toMillis.toString} ms processing (${(e1 + e2).toMillis.toString} ms total) | ||
""".stripMargin) | ||
|
||
case ProcessingFailure(s, a, l, e1, e2, t) => | ||
logger.warn( | ||
s"""Failed Resultset Processing: | ||
| | ||
| ${s.linesIterator.dropWhile(_.trim.isEmpty).mkString("\n ")} | ||
| | ||
| arguments = [${a.mkString(", ")}] | ||
| label = $l | ||
| elapsed = ${e1.toMillis.toString} ms exec + ${e2.toMillis.toString} ms processing (failed) (${(e1 + e2).toMillis.toString} ms total) | ||
| failure = ${t.getMessage} | ||
""".stripMargin) | ||
|
||
case ExecFailure(s, a, l, e1, t) => | ||
logger.error( | ||
s"""Failed Statement Execution: | ||
| | ||
| ${s.linesIterator.dropWhile(_.trim.isEmpty).mkString("\n ")} | ||
| | ||
| arguments = [${a.mkString(", ")}] | ||
| label = $l | ||
| elapsed = ${e1.toMillis.toString} ms exec (failed) | ||
| failure = ${t.getMessage} | ||
""".stripMargin) | ||
} | ||
} |