-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation covering all current aspects of the configuration f…
…ile (#308) * Add documentation covering all current aspects of the configuration file * ci: add lint workflow * chore: review markdown * docs: Add the configuration doc to docs.rs * chore: review comments. Bump min rust version * chore(docs): bump rust version in readme * fix(docs): markdown lint fixes for new doc and README * fix: missing newline * fix(ci): Resolve clippy issues * chore: move config docs, dedub section, add examples link
- Loading branch information
Showing
14 changed files
with
276 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
line-length: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
# Configuration | ||
|
||
log4rs can be configured programmatically by using the builders in the `config` | ||
module to construct a log4rs `Config` object, which can be passed to the | ||
`init_config` function. | ||
|
||
The more common configuration method, however, is via a separate config file. | ||
The `init_file` function takes the path to a config file as well as a | ||
`Deserializers` object which is responsible for instantiating the various | ||
objects specified by the config file. The following section covers the exact | ||
configuration syntax. Examples of both the programatic and configuration files | ||
can be found in the | ||
[examples directory](https://github.com/estk/log4rs/tree/master/examples). | ||
|
||
## Common Fields | ||
|
||
### LevelFilter's | ||
|
||
- Off | ||
- Error | ||
- Warn | ||
- Info | ||
- Debug | ||
- Trace | ||
|
||
### Filters | ||
|
||
The only accepted `filter` is of kind threshold with a level. The level must | ||
be a [LevelFilter](#levelfilters). One to many filters are allowed. | ||
|
||
i.e. | ||
|
||
```yml | ||
filters: | ||
- kind: threshold | ||
level: info | ||
``` | ||
### Encoder | ||
An `encoder` consists of a kind: the default which is pattern, or json. If | ||
pattern is defined, the default pattern `{d} {l} {t} - {m}{n}` is used unless | ||
overridden. Refer to | ||
[this documentation](https://docs.rs/log4rs/latest/log4rs/encode/pattern/index.html#formatters) | ||
for details regarding valid patterns. | ||
|
||
> Note that the json encoder does not have any additional controls such as the | ||
> pattern field. | ||
|
||
i.e. | ||
|
||
```yml | ||
encoder: | ||
kind: pattern | ||
pattern: "{h({d(%+)(utc)} [{f}:{L}] {l:<6} {M}:{m})}{n}" | ||
``` | ||
|
||
## Loggers | ||
|
||
A map of logger configurations. | ||
|
||
### Logger Configuration | ||
|
||
The _name_ of the logger is the yml tag. | ||
|
||
The _level_ of the logger is optional and defaults to the parents log level. | ||
The level must be a [LevelFilter](#levelfilters). | ||
|
||
The _appenders_ field is an optional list of [appenders](#appenders) attached | ||
to the logger. | ||
|
||
The _additive_ field is an optional boolean determining if the loggers parent | ||
will also be attached to this logger. The default is true. | ||
|
||
i.e. | ||
|
||
```yml | ||
loggers: | ||
my_logger: | ||
level: info | ||
appenders: | ||
- my_appender | ||
additive: true | ||
``` | ||
|
||
## The Root Logger | ||
|
||
Root is the required logger. It is the parent to all children loggers. To | ||
configure the Root, refer to [the logger section](#logger-configuration). | ||
|
||
> Note: The root logger has no parent and therefore cannot the _additive_ | ||
field does not apply. | ||
|
||
```yml | ||
root: | ||
level: info | ||
appenders: | ||
- my_appender | ||
``` | ||
|
||
## Appenders | ||
|
||
All appenders require a unique identifying string for each | ||
[appender configuration](#appender-config). | ||
|
||
### Appender Config | ||
|
||
Each Appender Kind has it's own configuration. However, all accept | ||
[filters](#filters). The `kind` field is required in an appender configuration. | ||
|
||
#### The Console Appender | ||
|
||
The _target_ field is optional and accepts `stdout` or `stderr`. It's default | ||
value is stdout. | ||
|
||
The _tty_only_ field is an optional boolean and dictates that the appender must | ||
only write when the target is a TTY. It's default value is false. | ||
|
||
The _encoder_ field is optional and can consist of multiple fields. Refer to | ||
the [encoder](#encoder) documention. | ||
|
||
```yml | ||
my_console_appender: | ||
kind: console | ||
target: stdout | ||
tty_only: false | ||
``` | ||
|
||
#### The File Appender | ||
|
||
The _path_ field is required and accepts environment variables of the form | ||
`$ENV{name_here}`. The path can be relative or absolute. | ||
|
||
The _encoder_ field is optional and can consist of multiple fields. Refer to | ||
the [encoder](#encoder) documention. | ||
|
||
The _append_ field is an optional boolean and defaults to `true`. True will | ||
append to the log file if it exists, false will truncate the existing file. | ||
|
||
```yml | ||
my_file_appender: | ||
kind: file | ||
path: $ENV{PWD}/log/test.log | ||
append: true | ||
``` | ||
|
||
#### The Rolling File Appender | ||
|
||
The rolling file configuration is by far the most complex. Like the | ||
[file appender](#the-file-appender), the path to the log file is required | ||
with the _append_ and the _encoders_ optional fields. | ||
|
||
i.e. | ||
|
||
```yml | ||
my_rolling_appender: | ||
kind: rolling_file | ||
path: "logs/test.log" | ||
policy: | ||
kind: compound | ||
trigger: | ||
kind: size | ||
limit: 1mb | ||
roller: | ||
kind: fixed_window | ||
base: 1 | ||
count: 5 | ||
pattern: "logs/test.{}.log" | ||
``` | ||
|
||
The new component is the _policy_ field. A policy must have `kind` like most | ||
other components, the default (and only supported) policy is `kind: compound`. | ||
|
||
The _trigger_ field is used to dictate when the log file should be rolled. The | ||
only supported trigger is `kind: size`. There is a required field `limit` | ||
which defines the maximum file size prior to a rolling of the file. The limit | ||
field requires one of the following units in bytes, case does not matter: | ||
|
||
- b | ||
- kb/kib | ||
- mb/mib | ||
- gb/gib | ||
- tb/tib | ||
|
||
i.e. | ||
|
||
```yml | ||
trigger: | ||
kind: size | ||
limit: 10 mb | ||
``` | ||
|
||
The _roller_ field supports two types: delete, and fixed_window. The delete | ||
roller does not take any other configuration fields. The fixed_window roller | ||
supports three fields: pattern, base, and count. The most current log file will | ||
always have the _base_ index. | ||
|
||
The _pattern_ field is used to rename files. The pattern must contain the | ||
double curly brace `{}`. For example `archive/foo.{}.log`. Each instance of | ||
`{}` will be replaced with the index number of the configuration file. Note | ||
that if the file extension of the pattern is `.gz` and the `gzip` Cargo | ||
feature is enabled, the archive files will be gzip-compressed. | ||
|
||
> Note: This pattern field is only used for archived files. The `path` field | ||
of the higher level `rolling_file` will be used for the active log file. | ||
|
||
The _base_ field is the starting index used to name rolling files. | ||
|
||
The _count_ field is the exclusive maximum index used to name rolling files. | ||
However, be warned that the roller renames every file when a log rolls over. | ||
Having a large count value can negatively impact performance. | ||
|
||
i.e. | ||
|
||
```yml | ||
roller: | ||
kind: fixed_window | ||
base: 1 | ||
count: 5 | ||
pattern: "archive/journey-service.{}.log" | ||
``` | ||
|
||
or | ||
|
||
```yml | ||
roller: | ||
kind: delete | ||
``` | ||
|
||
## Refresh Rate | ||
|
||
The _refresh_rate_ accepts a u64 value in seconds. The field is used to | ||
determine how often log4rs will scan the configuration file for changes. If a | ||
change is discovered, the logger will reconfigure automatically. | ||
|
||
i.e. | ||
|
||
```yml | ||
refresh_rate: 30 seconds | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.