-
Notifications
You must be signed in to change notification settings - Fork 125
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 #2355 from eikek/update-doobie
Update doobie to 1.0.0-RC4
- Loading branch information
Showing
9 changed files
with
71 additions
and
35 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
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
53 changes: 53 additions & 0 deletions
53
modules/store/src/main/scala/docspell/store/impl/DoobieLogging.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,53 @@ | ||
/* | ||
* Copyright 2020 Eike K. & Contributors | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
package docspell.store.impl | ||
|
||
import cats.Applicative | ||
import cats.syntax.all._ | ||
|
||
import docspell.logging.Logger | ||
import docspell.store.impl.DoobieLogging.LogLabel | ||
|
||
import doobie.util.log | ||
import doobie.util.log.LogHandler | ||
|
||
final class DoobieLogging[F[_]: Applicative](logger: Logger[F]) extends LogHandler[F] { | ||
override def run(logEvent: log.LogEvent): F[Unit] = | ||
if (LogLabel.fromEvent(logEvent).contains(LogLabel.Silent)) ().pure[F] | ||
else | ||
logEvent match { | ||
case log.Success(sql, args, _, exec, _) => | ||
logger.trace(s"SQL: $sql ($args) executed in $exec") | ||
|
||
case log.ProcessingFailure(sql, args, _, _, _, failure) => | ||
logger.error(failure)(s"SQL processing failed: $sql ($args)") | ||
|
||
case log.ExecFailure(sql, args, _, _, failure) => | ||
logger.error(failure)(s"SQL exec failed: $sql ($args)") | ||
} | ||
} | ||
|
||
object DoobieLogging { | ||
|
||
def apply[F[_]: Applicative](logger: Logger[F]): DoobieLogging[F] = | ||
new DoobieLogging[F](logger) | ||
|
||
sealed trait LogLabel extends Product { | ||
lazy val name: String = productPrefix.toLowerCase | ||
} | ||
object LogLabel { | ||
case object Silent extends LogLabel | ||
|
||
val all: List[LogLabel] = List(Silent) | ||
|
||
def fromString(str: String): Option[LogLabel] = | ||
all.find(_.name.equalsIgnoreCase(str)) | ||
|
||
def fromEvent(e: log.LogEvent): Option[LogLabel] = | ||
fromString(e.label) | ||
} | ||
} |
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
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