-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
Is there any way to do something like this?
Reference:
Example use case:
case class ExtendedTry[T](t: Try[T]) {
/** Logs a custom message in case of a failure of a given type, as a warning.
* @param message The custom message to be logged.
* @param log The logger instance is received implicitly or explicitly, such that it corresponds to the caller class.
* @tparam E The type of exception to be matched against.
* @return The same Try[T] instance, allowing it to chain operations.
*/
def logFailure[E <: Throwable : ClassTag](message: String, withTrace: Boolean = false)(implicit log: Logger)
: Try[T] = {
t.recover {
case failure: E => {
// Call here will print the file of the implicit Logger, but will print the line number in this file.
if(withTrace) log.warn(failure)(message) else log.warn(s"$message : ${failure.getMessage}")
}
}
t
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels