Skip to content

Commit

Permalink
Add logging derivator docs, fix LoggingBiMid
Browse files Browse the repository at this point in the history
  • Loading branch information
Odomontois committed Mar 24, 2021
1 parent 5b7efba commit 0c316ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,43 @@ import tofu.logging.bi.LoggingBiMidBuilder
import derevo.PassTypeArgs
import derevo.ParamRequire

/** Default logging derivation mechanism unary effect algebras,,
* adds logging around successful invocation of each method at DEBUG level
* class name is not printed by default
*
* for customization create object with same parents and abstract type member Result
* and redefine [onEnter] and [onLeave] methods of the LoggingMidBuilder trait
*/
object loggingMid
extends LoggingMidBuilder.Default with DerivationKN3[LoggingMid.Of] with PassTypeArgs with ParamRequire[Loggable] {
type Result[A] = LoggingMid[A]
def instance[U[f[_]]]: U[LoggingMid] = macro HigherKindedMacros.factorizeThis[U]
}

/** Default logging with errors derivation mechanism for unary effect algebras,
* adds logging around invocation of each method at DEBUG level and error alert at ERROR level
* class name is not printed by default
*
* for customization create object with same parents and abstract type member Result
* and redefine [onEnter], [onLeave] and [onFault] methods of the LoggingErrMidBuilder trait
*/
object loggingMidTry
extends LoggingErrMidBuilder.DefaultImpl[Throwable] with DerivationKN3[LoggingErrMid.Try] with PassTypeArgs
with ParamRequire[Loggable] {
with ParamRequire[Loggable] {
type Result[A] = LoggingErrMid[Throwable, A]
def instance[U[f[_]]]: U[Result] = macro HigherKindedMacros.factorizeThis[U]
}

/** Default logging with errors derivation mechanism for binary effect algebras,
* adds logging around invocation of each method at DEBUG level and error alert at ERROR level
* class name is not printed by default
*
* for customization create object with same parents and abstract type member Result
* and redefine [onEnter], [onLeave] methods of the LoggingBiMidBuilder trait
*/
object loggingBiMid
extends LoggingBiMidBuilder.Default with DerivationKN11[LoggingBiMid.Of] with PassTypeArgs
with ParamRequire[Loggable] {
with ParamRequire[Loggable] {
type Result[E, A] = LoggingBiMid[E, A]
def instance[U[f[_, _]]]: U[LoggingBiMid] =
macro HigherKindedMacros.bifactorizeThis[U]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object LoggingBiMidBuilder {
class Default extends LoggingBiMidBuilder {
def onEnter[F[_, _]](cls: Class[_], method: String, args: Seq[(String, LoggedValue)])(implicit
F: Logging.Safe[F]
): F[Nothing, Unit] = F.debug("entering {}.{} {}", cls.getName(), method, new ArgsLoggable(args))
): F[Nothing, Unit] = F.debug("entering {} {}", cls.getName(), method, new ArgsLoggable(args))

def onLeave[F[_, _]](
cls: Class[_],
Expand All @@ -74,7 +74,10 @@ object LoggingBiMidBuilder {
)(implicit
F: Logging.Safe[F]
): F[Nothing, Unit] =
F.debug("leaving {}.{} {}", cls.getName(), method, new ArgsLoggable(args))
if (ok)
F.debug("leaving {} {} result is {}", method, new ArgsLoggable(args), res)
else
F.error("error during {} {} error is {}", method, new ArgsLoggable(args), res)
}

class ArgsLoggable(values: Seq[(String, LoggedValue)]) extends LoggedValue {
Expand Down

0 comments on commit 0c316ac

Please sign in to comment.