From 38fd8efb89a7b0a893675b666ed40f154266f47a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 9 May 2022 00:07:56 +0200 Subject: [PATCH] Update docs --- README.md | 7 +++++-- doc/01-usage.md | 11 ++++++++--- doc/04-extending.md | 2 ++ doc/message-structure.md | 21 ++++++++++++++------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8a431d7e..ac7ec324 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ $ composer require monolog/monolog ```php pushProcessor(function ($record) { ``` Monolog provides some built-in processors that can be used in your project. -Look at the [dedicated chapter](https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md#processors) for the list. +Look at the [dedicated chapter](https://github.com/Seldaek/monolog/blob/main/doc/02-handlers-formatters-processors.md#processors) for the list. > Tip: processors can also be registered on a specific handler instead of the logger to apply only for this handler. @@ -165,6 +166,7 @@ You can easily grep through the log files filtering this or that channel. ```php formatted ``` -field in the log record to store its formatted value. Again, this field depends on the implementation of the *Handler* but is a good idea to **stick into the good practices and conventions of the project**. +property in the log record to store its formatted value. You can choose between predefined formatter classes or write your own (e.g. a multiline text file for human-readable output). @@ -206,7 +208,10 @@ You can choose between predefined formatter classes or write your own (e.g. a mu > > This formatter, as its name might indicate, is able to return a lineal string representation of the log record provided. > -> It is also capable to interpolate values from the log record, into the output format template used by the formatter to generate the final result, and in order to do it, you need to provide the log record values you are interested in, in the output template string using the form %value%, e.g: "'%context.foo% => %extra.foo%'" , in this example the values $record->context["foo"] and $record->extra["foo"] will be rendered as part of th final result. +> It is also capable to interpolate values from the log record, into the output format template used by the formatter to generate +> the final result, and in order to do it, you need to provide the log record values you are interested in, in the output template +> string using the form %value%, e.g: "'%context.foo% => %extra.foo%'" , in this example the values `$record->context["foo"]` +> and `$record->extra["foo"]` will be rendered as part of the final result. In the following example, we demonstrate how to: 1. Create a `LineFormatter` instance and set a custom output format template. diff --git a/doc/04-extending.md b/doc/04-extending.md index 8d9d09a4..a57c70b7 100644 --- a/doc/04-extending.md +++ b/doc/04-extending.md @@ -21,6 +21,8 @@ abstract class provided by Monolog to keep things DRY. ```php 'John']` as context will be written as "User John logged in". -level | int | Severity of the log message. See log levels described in [01-usage.md](01-usage.md#log-levels). -level_name | string | String representation of log level. +level | Monolog\Level case | Severity of the log message. See log levels described in [01-usage.md](01-usage.md#log-levels). +levelName | Monolog\LevelName case | String representation of log level. context | array | Arbitrary data passed with the construction of the message. For example the username of the current user or their IP address. channel | string | The channel this message was logged to. This is the name that was passed when the logger was created with `new Logger($channel)`. datetime | Monolog\DateTimeImmutable | Date and time when the message was logged. Class extends `\DateTimeImmutable`. extra | array | A placeholder array where processors can put additional data. Always available, but empty if there are no processors registered. At first glance `context` and `extra` look very similar, and they are in the sense that they both carry arbitrary data that is related to the log message somehow. -The main difference is that `context` can be supplied in user land (it is the 3rd parameter to `Logger::addRecord()`) whereas `extra` is internal only and can be filled by processors. -The reason processors write to `extra` and not to `context` is to prevent overriding any user-provided data in `context`. +The main difference is that `context` can be supplied in user land (it is the 3rd parameter to `Psr\Log\LoggerInterface` methods) whereas `extra` is internal only +and can be filled by processors. The reason processors write to `extra` and not to `context` is to prevent overriding any user-provided data in `context`. + +All properties except `extra` are read-only. + +> Note: For BC reasons with Monolog 1 and 2 which used arrays, `LogRecord` implements `ArrayAccess` so you can access the above properties +> using `$record['message']` for example, with the notable exception of `levelName` which must be referred to as `level_name` for BC.