Trait/Object

olon.common

BoxLogging

Related Docs: object BoxLogging | package common

Permalink

trait BoxLogging extends AnyRef

Mix this trait in to get some low-cost implicits for logging boxes easily. The consumer will need to implement a logBoxError method to log messages with an optional Throwable, as well as its related friends for trace, debug, info, and warn levels. This allows abstracting out where and what the actual logger is.

With this mixed in, boxes will have logFailure and logFailure methods. The first logs all Failures as well as Empty. The second logs only Failures and ParamFailures, treating Empty as a valid value. These both log their respective items at ERROR level. You can also use traceLog*, debugLog*, infoLog*, and warnLog* if you want to log at other levels (e.g., you can use infoLogFailure to log an Empty or Failure at INFO level).

All of these return the box unchanged, so you can continue to use it in for comprehensions, call openOr on it, etc.

There is an implementation for anyone who wants to use Lift's Loggable trait called LoggableBoxLogging. Another implementaiton is available for use with a plain SLF4J logger, SLF4JBoxLogging. You can also implement a version for any other logging adapter. Lastly, you can simply import BoxLogging._ to get the methods available at a top level; however, note that using them this way will lose information about where the log message came from.

Here is an example of how you might use this in system that executes a third- party service and notifies another system of failures.

val systemResult: Box[ServiceReturn] =
  system
    .executeService(true, requester)
    .map(...)
    .logFailure("Failed to execute service") match {
      case Full(content) =>
        content
      case failure: Failure =>
        otherSystem.notifyFailure(failure)
      case Empty =>
        otherSystem.notifyFailure(Failure("No idea what happened."))
    }
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BoxLogging
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. implicit class LogEmptyOrFailure[T] extends AnyRef

    Permalink

Abstract Value Members

  1. abstract def logBoxDebug(message: String, throwable: Option[Throwable]): Unit

    Permalink

    Called with a debug message and possibly a throwable that caused the issue in question.

    Called with a debug message and possibly a throwable that caused the issue in question. Should DEBUG log the message and the throwable.

    Exists in order to abstract away logger abstractions. Abstractception, as it were.

    Attributes
    protected
  2. abstract def logBoxError(message: String, throwable: Option[Throwable]): Unit

    Permalink

    Called with an error message and possibly a throwable that caused the error in question.

    Called with an error message and possibly a throwable that caused the error in question. Should ERROR log the message and the throwable.

    Exists in order to abstract away logger abstractions. Abstractception, as it were.

    Attributes
    protected
  3. abstract def logBoxInfo(message: String, throwable: Option[Throwable]): Unit

    Permalink

    Called with an info message and possibly a throwable that caused the issue in question.

    Called with an info message and possibly a throwable that caused the issue in question. Should INFO log the message and the throwable.

    Exists in order to abstract away logger abstractions. Abstractception, as it were.

    Attributes
    protected
  4. abstract def logBoxTrace(message: String, throwable: Option[Throwable]): Unit

    Permalink

    Called with a trace message and possibly a throwable that caused the issue in question.

    Called with a trace message and possibly a throwable that caused the issue in question. Should TRACE log the message and the throwable.

    Exists in order to abstract away logger abstractions. Abstractception, as it were.

    Attributes
    protected
  5. abstract def logBoxWarn(message: String, throwable: Option[Throwable]): Unit

    Permalink

    Called with a warn message and possibly a throwable that caused the issue in question.

    Called with a warn message and possibly a throwable that caused the issue in question. Should WARN log the message and the throwable.

    Exists in order to abstract away logger abstractions. Abstractception, as it were.

    Attributes
    protected

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  9. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  10. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  11. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  13. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  14. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  15. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  16. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @Deprecated @deprecated @throws( classOf[java.lang.Throwable] )
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

Ungrouped