Class/Object

org.scalawag.timber.api

BaseLogger

Related Docs: object BaseLogger | package api

Permalink

class BaseLogger extends AnyRef

Embodies the main interface into timber. Instances of this class are very simple objects that are essentially entry factories. They are used to create entries and pass them to a dispatcher for handling, after gathering some additional contextual information. Every BaseLogger has its associated dispatcher established at construction-time. This dispatcher dispatches all of the entries that this logger creates throughout its lifetime, since the dispatcher can not be changed after construction.

Instances of this class are lightweight, immutable and thread-safe. You should not go to great lengths to avoid creating loggers.

In addition to gathering contextual information, BaseLoggers can be given attributes and tags that will be applied to all the entries they create. Given that they are lightweight, this gives you a way to associated some shared statically-scoped attributes with certain entries across threads, where the thread executing the code is not as important as the static attributes. This can be particularly useful when using scala Futures or a similar technology where threads become more fungible. Here is an example where the thread context (which is normally how you would associate the same data with several log calls) becomes meaningless.

import scala.util._
import scala.concurrent.Future
import org.scalawag.timber.api._
import scala.concurrent.ExecutionContext.Implicits.global

def handleRequest(clientIp:String) {
  val logger = new Logger(Map("clientIp" -> clientIp))
  logger.debug("about to start handling request")
  Future {
    logger.debug("handling request")
  } onComplete {
    case Success(_) =>
      logger.debug("request handled")
    case Failure(ex) =>
      logger.debug(s"failed to handle request: $$ex")
  }
}

You could also pass the static context (clientIp) to each log call individually, but the style shown here is a little cleaner and less error-prone.

BaseLoggers don't support the isEnabled type methods provided by some other logging systems. That's because the logger doesn't make any decisions regarding if (or where) the entries it creates are actually processed in any way. You don't need to protect against message generation overhead because messages are lazily built (unless you specify the ImmediateMessage tag). Anything else that you would do in application code that depends on the status of the logging system is probably a bad idea.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. BaseLogger
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new BaseLogger(attributes: (String, Any)*)(implicit dispatcher: Dispatcher)

    Permalink
  2. new BaseLogger(attributes: Map[String, Any] = Map.empty, tags: Set[Tag] = Set.empty)(implicit dispatcher: Dispatcher)

    Permalink

    attributes

    the logger attributes that this logger associates with the entries it creates

    tags

    the tags that this logger associates with the entries it creates

    dispatcher

    the dispatcher that is used to dispatch the entries that this logger creates

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. val attributes: Map[String, Any]

    Permalink

    the logger attributes that this logger associates with the entries it creates

  6. def buildEntry(level: Option[Level], message: Option[Message], location: Option[LogCallLocation], entryTags: TraversableOnce[Tag]): Entry

    Permalink
    Attributes
    protected
  7. def clone(): AnyRef

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. def log(implicit location: LogCallLocation): Unit

    Permalink

    Submits an entry without a level, a Message or tags to the logging system.

    Submits an entry without a level, a Message or tags to the logging system. This essentially creates an entry with nothing but automatically-collected call metadata.

    location

    the source location of the method call (usually automatically fulfilled by LogCallLocation.capture())

  15. def log(message: Message)(implicit location: LogCallLocation): Unit

    Permalink

    Submits an entry with a Message but no level or tags to the logging system.

    Submits an entry with a Message but no level or tags to the logging system.

    message

    the message to include with the entry

    location

    the source location of the method call (usually automatically fulfilled by LogCallLocation.capture())

  16. def log(level: Level)(message: Message)(implicit location: LogCallLocation): Unit

    Permalink

    Submits an entry with a Message and level but no tags to the logging system.

    Submits an entry with a Message and level but no tags to the logging system.

    The message argument appears in an argument list by itself because this allows us to use a thunk or a tuple as the source of the implicit Message conversion. When it appears with other arguments, the appearance of the calling syntax goes downhill fast (e.g., having to wrap the thunk in parentheses or having to include extra parentheses around tuples). Similarly, tags is not a varargs parameter because the compiler prefers to perceive multiple arguments as possible Tags (and failing) rather than look for an implicit conversion from the tuple.

    level

    the level to use for the entry created

    message

    the message to include with the entry

    location

    the source location of the method call (usually automatically fulfilled by LogCallLocation.capture())

  17. def log(tags: TraversableOnce[Tag])(message: Message)(implicit location: LogCallLocation): Unit

    Permalink

    Submits an entry with a Message and tags but no level to the logging system.

    Submits an entry with a Message and tags but no level to the logging system.

    The message argument appears in an argument list by itself because this allows us to use a thunk or a tuple as the source of the implicit Message conversion. When it appears with other arguments, the appearance of the calling syntax goes downhill fast (e.g., having to wrap the thunk in parentheses or having to include extra parentheses around tuples). Similarly, tags is not a varargs parameter because the compiler prefers to perceive multiple arguments as possible Tags (and failing) rather than look for an implicit conversion from the tuple.

    tags

    additional tags to include with the entry

    message

    the message to include with the entry

    location

    the source location of the method call (usually automatically fulfilled by LogCallLocation.capture())

  18. def log(level: Level, tags: TraversableOnce[Tag] = Iterable.empty)(message: Message)(implicit location: LogCallLocation): Unit

    Permalink

    Submits an entry with a level, a message and maybe tags to the logging system.

    Submits an entry with a level, a message and maybe tags to the logging system.

    The message argument appears in an argument list by itself because this allows us to use a thunk or a tuple as the source of the implicit Message conversion. When it appears with other arguments, the appearance of the calling syntax goes downhill fast (e.g., having to wrap the thunk in parentheses or having to include extra parentheses around tuples). Similarly, tags is not a varargs parameter because the compiler prefers to perceive multiple arguments as possible Tags (and failing) rather than look for an implicit conversion from the tuple.

    level

    the level to use for the entry created

    tags

    additional tags to include with the entry

    message

    the message to include with the entry

    location

    the source location of the method call (usually automatically fulfilled by LogCallLocation.capture())

  19. final def ne(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef
  21. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  23. val tags: Set[Tag]

    Permalink

    the tags that this logger associates with the entries it creates

  24. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  25. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped