Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalawag
    Definition Classes
    org
  • package timber
    Definition Classes
    scalawag
  • package api
    Definition Classes
    timber
  • package impl
    Definition Classes
    api
  • package level

    Contains composable traits that can be used to add many common level-specific log methods to your custom loggers.

    Contains composable traits that can be used to add many common level-specific log methods to your custom loggers. They are inspired by various legacy logging technologies.

    Each trait defines several methods for logging and level val that can be overridden to control the level at which those methods log entries. See Logger for an example.

    Another example that mixes in a ridiculous set of level methods:

    import org.scalawag.timber.api
    import org.scalawag.timber.api.Dispatcher
    import org.scalawag.timber.api.level._
    
    class Logger(override val attributes:Map[String,Any] = Map.empty, override val tags:Set[Tag] = Set.empty)(implicit dispatcher: Dispatcher)
      extends BaseLogger(attributes, tags)(dispatcher) with Emergency with Finest with Warning with Warn
    Definition Classes
    api
  • package style
    Definition Classes
    api
  • BaseLogger
  • Dispatcher
  • Entry
  • ImmediateMessage
  • Level
  • Logger
  • Message
  • Tag
  • ThreadAttributes

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. Protected

Instance Constructors

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

    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
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. val attributes: Map[String, Any]
  6. def buildEntry(level: Option[Level], message: Option[Message], location: Option[LogCallLocation], entryTags: TraversableOnce[Tag]): Entry
    Attributes
    protected
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. def log(implicit location: LogCallLocation): Unit

    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

    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

    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

    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

    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
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  23. val tags: Set[Tag]
  24. def toString(): String
    Definition Classes
    AnyRef → Any
  25. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  26. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped