Skip to content

Provided Formatters

Jerome Duquennoy edited this page Mar 6, 2018 · 11 revisions

Formatters

Formatters are in charge of transforming the message to make it fit a pre-defined format.

There is currently only one formatter available : the pattern formatter.

The pattern formatter

This formatter will add textual elements around the message, following a pattern provided at creation time.

The descriptive format is composed of text, markers, and marker options.

  • A marker is a single character that forwards a '%'. This marker is case sensitive. For example : %d, %m, %n ...
  • A marker option appears just after a marker, in the form of JSON text : {'name': 'value', 'name ': 'value'}
  • Everything that is neither a marker nor a marker option is considered as text, that will be copied in the formatted message

Available markers

Letter Specific options Description
l - The [[level
n - The name (the identifier) of the logger to which the message has been sent
d format : A date format using [[the strftime format http://man7.org/linux/man-pages/man3/strftime.3.html]].
D format : A date format using [[the NSDateFormatter format http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns]].
L -  The number of the line where the log was issued. Require use of specific log methods with file and line parameters when calling from Objective-C code.
F -  The path of the file from where the log was issued. Require use of specific log methods with file and line parameters when calling from Objective-C code.
f - The name of the file from where the log was issued. Require use of specific log methods with file and line parameters when calling from Objective-C code.
M - The name of the method from where the log was issued. Require use of specific log methods with file and line parameters when calling from Objective-C code.
t - The id of the current thread in hexadecimal notation.
T - The name of the current thread of GCD queue.
p - The id of the current process of GCD queue.
m - The log message itself
% -  The '%' character

Options available to all markers

Those options can be used in the configuration section of any of the markers.

Name Value Description
padding A integer (positive or negative) Specify a fixed length for the the content of the marker. If the content is longer than the pad, it is truncated. If the content is shorter, spaces are added. If the value is negative, the padding will happen on the left. If the value is positive, the padding will happen on the right.

Configuration parameters

Class (to use in configuration dictionary) : PatternFormatter

| Propery name | Configuration dictionary parameter | description | Default value | |---|---|---|---|---| | no property, provided at init time | Pattern | The pattern to use to format a message | No default value, this parameter is mandatory. |

Example patterns

Pattern Result
%d{%F %H:%M:%S} - %l # %m 2015-07-31 23:55:15 - Debug # The log message
%F:%L:1: %l: %m /path/to/sourceFile.swift:85:1: error: The error message