Is there any way to do something like this?
Reference:
http://stackoverflow.com/questions/1486233/java-logging-show-the-source-line-number-of-the-caller-not-the-logging-helper
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
}
}
Is there any way to do something like this?
Reference:
http://stackoverflow.com/questions/1486233/java-logging-show-the-source-line-number-of-the-caller-not-the-logging-helper
Example use case: