Module log4rs::encode::pattern [] [src]

A simple pattern-based encoder.

The supported syntax is similar to that used by Rust's string formatting infrastructure. It consists of text which will be output verbatim, with formatting specifiers denoted by braces containing the configuration of the formatter. This consists of a formatter name followed optionally by a parenthesized argument. A subset of the standard formatting parameters is also supported.

Supported Formatters

  • d, date - The current time. By default, the ISO 8601 format is used. A custom format may be provided in the syntax accepted by chrono as an argument.
  • f, file - The source file that the log message came from.
  • l, level - The log level.
  • L, line - The line that the log message came from.
  • m, message - The log message.
  • M, module - The module that the log message came from.
  • t, target - The target of the log message.
  • T, thread - The name of the thread that the log message came from.
  • n - A newline.

In addition, an "unnamed" formatter exists to apply parameters (see below) to an entire group of formatters.

Supported Parameters

Left and right alignment with a custom fill character and width is supported. In addition, the "precision" parameter can be used to set a maximum length for formatter output.

Examples

The default pattern is {d} {l} {t} - {m}{n} which produces output like 2016-03-20T22:22:20.644420340+00:00 INFO module::path - this is a log message.

The pattern {d(%Y-%m-%d %H:%M:%S)} will output the current time with a custom format looking like 2016-03-20 22:22:20.

The pattern {m:>10.15} will right-align the log message to a minimum of 10 bytes, filling in with space characters, and truncate output after 15 bytes. The message hello will therefore be displayed as hello, while the message hello there, world! will be displayed as hello there, wo.

The pattern {({l} {m}):15.15} will output the log level and message limited to exactly 15 bytes, padding with space characters on the right if necessary. The message hello and log level INFO will be displayed as INFO hello , while the message hello, world! and log level DEBUG will be truncated to DEBUG hello, wo.

Structs

PatternEncoder

An Encoder configured via a format string.

PatternEncoderDeserializer

A deserializer for the PatternEncoder.