package formatter
Contains functionality for turning log entries into text.
- Alphabetic
- By Inheritance
- formatter
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Package Members
Type Members
- trait EntryFormatter extends Formatter[Entry]
Converts an Entry into text.
- trait Formatter[-T] extends AnyRef
Converts something into text.
Converts something into text. Implementations of this trait must be thread-safe.
- T
the type of object that this formatter can turn into text.
- class ProgrammableEntryFormatter extends EntryFormatter
Formats entries using the specified metadata providers to create a header.
Formats entries using the specified metadata providers to create a header. The metadata providers can be specified using the mini-DSL on the
entryobject:threadName- the name of the thread that created the entrytimestamp- the timestamp at which the entry was createdlevel- the level at which the entry was created (if available)loggingClass- the class from which the log method was called (if available)loggingMethod- the method from which the log method was called (if available)sourceLocation- the location in source (file name and line number) from which the log method was called (if available)tags- the tags associated with the entryloggerAttributes- the logger attributes associated with the entrythreadAttributes- the thread attributes associated with the entryloggerAttribute(name)- the logger attribute with the specified name associated with the entry (if available)threadAttribute(name)- the thread attribute with the specified name associated with the entry (if available)
new ProgrammableEntryFormatter(Seq(entry.threadName,entry.loggingClass))
You can also specify Strings to be included literally.
new ProgrammableEntryFormatter(Seq("literal",entry.loggingClass))
In addition to the providers above, you can specify some modifiers to tweak them before their inclusion:
formattedWith- allows you to choose how the metadata is formatted, must match the type of the metadatamap- allows you to apply an arbitrary mapping function to the metadata before inclusionwithout- allows you to remove keys from a map before inclusion (e.g., if you already included on of the keys specifically)
If you don't specify a formatter, the
toStringmethod of the object will be used. There are some built-in formatters for timestamps and levels that you can use. There are also some built-in formatters for any Iterables that may be more appealing than the defaulttoStringimplementation.Commas- formats Iterables as strings with commas separating the itemsSpaces- formats Iterables as strings with spaces separating the itemsDelimiter(str)- formats Iterables as strings with the specified delimiter separating the itemsCommasAndEquals- formats Maps as equals-separated pairs separated by commas (e.g.,k1=v1,k2=v2)
entry.timestamp formattedWith HumanReadableTimestampFormatter entry.timestamp formattedWith SimpleDateFormatTimestampFormatter("yyyy/MM/dd") entry.threadName map { name => name.length } entry.loggerAttributes without "name" formattedWith CommasAndEquals
For the metadata that may not be present (indicated with "if available" above), you can specify a fallback to use when it's absent with
orElse. You can't useorElseafter a metadata provider that will definitely return something.entry.loggingClass orElse entry.loggerAttribute("name") orElse "unknown"
With certain combinations of modifiers, you may have to include parentheses if the scala compiler can't figure out the operator precedence. You can also specify the modifiers without utilizing the infix call style, if you prefer.
Value Members
- object DefaultEntryFormatter extends ProgrammableEntryFormatter
Formats the entries for receivers that require a formatter and don't specify an alternate.
- object MessageOnlyEntryFormatter extends EntryFormatter
- object ProgrammableEntryFormatter
Most of the declarations in this object should be used through the DSL.
Most of the declarations in this object should be used through the DSL. See ProgrammableEntryFormatter for more information.