-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from dotkernel/issue-49
Removed laminas-log dependency
- Loading branch information
Showing
52 changed files
with
2,616 additions
and
153 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
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,10 @@ | ||
# Adding The Config Provider | ||
|
||
* In `config/config.php` add an entry for the config provider `\Dot\Log\ConfigProvider::class` | ||
* Make sure it is added before with the Application-Specific components, eg.: | ||
* `\Frontend\App\ConfigProvider.php` | ||
* `\Admin\App\ConfigProvider::class` | ||
* `\MyProject\ConfigProvider::class` etc. | ||
* Add the logger configuration in an autoload config file, e.g. you can create `config/autoload/logger.global.php`. Follow the `Configuring the writer(s)` chapter for a simple working example. | ||
|
||
Note: `Dot\Log\ConfigProvider` has an abstract factory `LoggerAbstractServiceFactory::class` which corresponds to the alias, not the class name. Instead of requesting `Dot\Log\Logger::class` from the container, use `dot-log.my_logger`. |
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,40 @@ | ||
# Configuring the writer(s) | ||
|
||
Loggers must have at least one writer. | ||
|
||
A writer is an object that inherits from `Dot\Log\Writer\AbstractWriter`. A writer's responsibility is to record log data to a storage backend. | ||
|
||
## Writing to a file (stream) | ||
|
||
You can separate logs into multiple files using writers and filters. For example *warnings.log*, *errors.log*, *all_messages.log*. | ||
|
||
The following is the simplest example to write all log messages to `/log/dk.log` | ||
|
||
```php | ||
return [ | ||
'dot_log' => [ | ||
'loggers' => [ | ||
'my_logger' => [ | ||
'writers' => [ | ||
'FileWriter' => [ | ||
'name' => 'FileWriter', | ||
'priority' => \Dot\Log\Manager\Logger::ALERT, // this is equal to 1 | ||
'options' => [ | ||
'stream' => __DIR__ . '/../../log/dk.log', | ||
], | ||
], | ||
], | ||
] | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
* The `FileWriter` key is optional, otherwise the writers array would be enumerative instead of associative. | ||
* The `name` key is a developer-provided name for that writer, the writer name key is **mandatory**. | ||
|
||
The `priority` key does not affect the errors that are written. It is a way to organize writers. | ||
|
||
The `priority` key is optional. | ||
|
||
The key `stream` is required only if writing into streams/files. |
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,41 @@ | ||
# Example with formatter | ||
|
||
* The log is used through `dot-log` | ||
* The logger name is `my_logger` | ||
* It writes to file: `log/dk.log` | ||
* It is configured to explicitly write all messages | ||
* The messages are formatted as JSON | ||
|
||
```php | ||
<?php | ||
return [ | ||
'dot_log' => [ | ||
'loggers' => [ | ||
'my_logger' => [ | ||
'writers' => [ | ||
'FileWriter' => [ | ||
'name' => 'FileWriter', | ||
'priority' => \Dot\Log\Manager\Logger::ALERT, | ||
'options' => [ | ||
'stream' => __DIR__ . '/../../log/dk.log', | ||
// explicitly log all messages | ||
'filters' => [ | ||
'allMessages' => [ | ||
'name' => 'priority', | ||
'options' => [ | ||
'operator' => '>=', | ||
'priority' => \Dot\Log\Manager\Logger::EMERG, | ||
], | ||
], | ||
], | ||
'formatter' => [ | ||
'name' => \Dot\Log\Manager\Formatter\Json::class, | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
``` |
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,95 @@ | ||
# Filtering log messages | ||
|
||
The following conforms to the `PSR-3: Logger Interface` document. | ||
|
||
The log levels are in order of priority/importance: | ||
|
||
* emergency (0) | ||
* alert (1) | ||
* critical (2) | ||
* error (3) | ||
* warning (4) | ||
* notice (5) | ||
* info (6) | ||
* debug (7) | ||
|
||
Although the plain Logger in `dot-log` is not fully compatible with PSR-3, it provides a way to log all of these message types. | ||
|
||
The following example has three file writers using filters: | ||
|
||
* First Example: `FileWriter` - All messages are logged in `/log/dk.log` | ||
* Second Example: `OnlyWarningsWriter` - Only warnings are logged in `/log/warnings.log` | ||
* Third Example: `WarningOrHigherWriter` - All important messages (`warnings` or critical) are logged in `/log/important_messages.log` | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'dot_log' => [ | ||
'loggers' => [ | ||
'my_logger' => [ | ||
'writers' => [ | ||
'FileWriter' => [ | ||
'name' => 'FileWriter', | ||
'priority' => \Dot\Log\Manager\Logger::ALERT, | ||
'options' => [ | ||
'stream' => __DIR__ . '/../../log/dk.log', | ||
'filters' => [ | ||
'allMessages' => [ | ||
'name' => 'priority', | ||
'options' => [ | ||
'operator' => '>=', | ||
'priority' => \Dot\Log\Manager\Logger::EMERG, | ||
] | ||
], | ||
], | ||
], | ||
], | ||
// Only warnings | ||
'OnlyWarningsWriter' => [ | ||
'name' => 'stream', | ||
'priority' => \Dot\Log\Manager\Logger::ALERT, | ||
'options' => [ | ||
'stream' => __DIR__ . '/../../log/warnings_only.log', | ||
'filters' => [ | ||
'warningOnly' => [ | ||
'name' => 'priority', | ||
'options' => [ | ||
'operator' => '==', | ||
'priority' => \Dot\Log\Manager\Logger::WARN, | ||
], | ||
], | ||
], | ||
], | ||
], | ||
// Warnings and more important messages | ||
'WarningOrHigherWriter' => [ | ||
'name' => 'stream', | ||
'priority' => \Dot\Log\Manager\Logger::ALERT, | ||
'options' => [ | ||
'stream' => __DIR__ . '/../../log/important_messages.log', | ||
'filters' => [ | ||
'importantMessages' => [ | ||
'name' => 'priority', | ||
'options' => [ | ||
// note, the smaller the priority, the more important is the message | ||
// 0 - emergency, 1 - alert, 2- error, 3 - warn etc. | ||
'operator' => '<=', | ||
'priority' => \Dot\Log\Manager\Logger::WARN, | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
As in the writer configuration, the developer can optionally use keys for associating the filters with a name. | ||
|
||
IMPORTANT NOTE: the operator for more important messages is `<=`, this is because the number representation is smaller for a more important message type. | ||
|
||
The filter added on the first writer is equivalent to not setting a filter, but it was added to illustrate the usage of the operator to explicitly allow all messages. |
Oops, something went wrong.