Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented PSR3 #68

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# dot-log

Robust, composite PSR-3 compliant logger with filtering and formatting.

## Documentation

Documentation is available at: https://docs.dotkernel.org/dot-log/.

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-log)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/4.1.1)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/5.0.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/blob/4.0/LICENSE.md)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-log)](https://github.com/dotkernel/dot-log/blob/5.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml)
[![Build Static](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-log/graph/badge.svg?token=JX19KTBRCZ)](https://codecov.io/gh/dotkernel/dot-log)

## Adding The Config Provider
Expand Down Expand Up @@ -43,7 +51,7 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Dot\Log\Manager\Logger::ALERT, // this is equal to 1
'level' => \Dot\Log\Logger::ALERT, // this is equal to 1
'options' => [
'stream' => __DIR__ . '/../../log/dk.log',
],
Expand All @@ -58,9 +66,9 @@ return [
* The `FileWriter` key is optional, otherwise the writers array would be enumerative instead of associative.
* The writer name key is a developer-provided name for that writer, the writer name key is **mandatory**.

The writer priority key is not affecting the errors that are written, it is a way to organize writers.
The writer level key is not affecting the errors that are written, it is a way to organize writers.

The writer priority key is optional.
The writer level key is optional.

To write into a file the key stream must be present in the writer options array. This is required only if writing into streams/files.

Expand All @@ -79,9 +87,7 @@ The full list of format specifiers is available [here](https://www.php.net/manua

As per PSR-3 document.

The log levels are: emergency (0), alert (1), critical (2), error (3), warn (4), notice (5), info (6), debug (7) (in order of priority/importance)

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 log levels are: emergency (0), alert (1), critical (2), error (3), warn (4), notice (5), info (6), debug (7) (in order of level/importance)

The following example has three file writers using filters:

Expand All @@ -98,33 +104,33 @@ return [
'my_logger' => [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'name' => 'FileWriter',
'level' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/dk.log',
'filters' => [
'allMessages' => [
'name' => 'priority',
'name' => 'level',
'options' => [
'operator' => '>=',
'priority' => \Dot\Log\Manager\Logger::EMERG,
'level' => \Dot\Log\Logger::EMERG,
]
],
],
],
],
// Only warnings
'OnlyWarningsWriter' => [
'name' => 'stream',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'name' => 'stream',
'level' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/warnings_only.log',
'filters' => [
'warningOnly' => [
'name' => 'priority',
'name' => 'level',
'options' => [
'operator' => '==',
'priority' => \Dot\Log\Manager\Logger::WARN,
'level' => \Dot\Log\Logger::WARN,
],
],
],
Expand All @@ -133,17 +139,17 @@ return [
// Warnings and more important messages
'WarningOrHigherWriter' => [
'name' => 'stream',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'level' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/important_messages.log',
'filters' => [
'importantMessages' => [
'name' => 'priority',
'name' => 'level',
'options' => [
// note, the smaller the priority, the more important is the message
// note, the smaller the level, the more important is the message
// 0 - emergency, 1 - alert, 2- error, 3 - warn. .etc
'operator' => '<=',
'priority' => \Dot\Log\Manager\Logger::WARN,
'level' => \Dot\Log\Logger::WARN,
],
],
],
Expand Down Expand Up @@ -181,7 +187,7 @@ The following formats the message as JSON data:

```php
'formatter' => [
'name' => \Dot\Log\Manager\Formatter\Json::class,
'name' => \Dot\Log\Formatter\Json::class,
],
```

Expand All @@ -203,22 +209,22 @@ return [
'my_logger' => [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'name' => 'FileWriter',
'level' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/dk.log',
// explicitly log all messages
'filters' => [
'allMessages' => [
'name' => 'priority',
'name' => 'level',
'options' => [
'operator' => '>=',
'priority' => \Dot\Log\Manager\Logger::EMERG,
'level' => \Dot\Log\Logger::EMERG,
],
],
],
'formatter' => [
'name' => \Dot\Log\Manager\Formatter\Json::class,
'name' => \Dot\Log\Formatter\Json::class,
],
],
],
Expand All @@ -236,7 +242,7 @@ Basic usage of the logger is illustrated below.
The messages are written to see which logs are written and which are not written.

```php
use Dot\Log\Manager\Logger;
use Dot\Log\Logger;
```

...
Expand All @@ -245,15 +251,13 @@ use Dot\Log\Manager\Logger;
$logger = $container->get('dot-log.my_logger');

/** @var Logger $logger */
$logger->emerg('0 EMERG');
$logger->emergency('0 EMERG');
$logger->alert('1 ALERT');
$logger->crit('2 CRITICAL');
$logger->err('3 ERR');
$logger->warn('4 WARN');
$logger->critical('2 CRITICAL');
$logger->error('3 ERR');
$logger->warning('4 WARN');
$logger->notice('5 NOTICE');
$logger->info('6 INF');
$logger->debug('7 debug');
$logger->log(Logger::NOTICE, 'NOTICE from log()');
```

Extracted from [this article](https://www.dotkernel.com/dotkernel/logging-with-dot-log-in-mezzio-and-dotkernel)
8 changes: 5 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
## Supported Versions


| Version | Supported | PHP Version |
|---------|--------------------|----------------------------------------------------------------------------------------------------|
| Version | Supported | PHP Version |
|---------|--------------------|---------------------------------------------------------------------------------------------------------|
| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/5.0.0) |
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/4.1.0) |
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-log/3.4.7) |
| <= 2.x | :x: | |
| <= 2.x | :x: | |


## Reporting Potential Security Issues
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "dotkernel/dot-log",
"type": "library",
"description": "Dotkernel log component extending and customizing laminas-log",
"description": "Dotkernel log component implementing PSR-3",
"license": "MIT",
"homepage": "https://github.com/dotkernel/dot-log",
"keywords": [
"log",
"logging",
"services",
"mezzio",
"laminas",
"laminas-log"
"PSR-3"
],
"authors": [
{
Expand All @@ -21,7 +19,8 @@
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"laminas/laminas-servicemanager": "^4.0",
"laminas/laminas-validator": "^3.0"
"laminas/laminas-validator": "^3.0",
"psr/log": "^3.0.2"
},
"require-dev": {
"laminas/laminas-coding-standard": "^3.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/book/v4/configuring-writer.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Dot\Log\Manager\Logger::ALERT, // this is equal to 1
'priority' => \Dot\Log\Logger::ALERT, // this is equal to 1
'options' => [
'stream' => __DIR__ . '/../../log/dk.log',
],
Expand Down
6 changes: 3 additions & 3 deletions docs/book/v4/example-with-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'priority' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/dk.log',
// explicitly log all messages
Expand All @@ -24,12 +24,12 @@ return [
'name' => 'priority',
'options' => [
'operator' => '>=',
'priority' => \Dot\Log\Manager\Logger::EMERG,
'priority' => \Dot\Log\Logger::EMERG,
],
],
],
'formatter' => [
'name' => \Dot\Log\Manager\Formatter\Json::class,
'name' => \Dot\Log\Formatter\Json::class,
],
],
],
Expand Down
12 changes: 6 additions & 6 deletions docs/book/v4/filtering-log-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'priority' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/dk.log',
'filters' => [
'allMessages' => [
'name' => 'priority',
'options' => [
'operator' => '>=',
'priority' => \Dot\Log\Manager\Logger::EMERG,
'priority' => \Dot\Log\Logger::EMERG,
]
],
],
Expand All @@ -48,15 +48,15 @@ return [
// Only warnings
'OnlyWarningsWriter' => [
'name' => 'stream',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'priority' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/warnings_only.log',
'filters' => [
'warningOnly' => [
'name' => 'priority',
'options' => [
'operator' => '==',
'priority' => \Dot\Log\Manager\Logger::WARN,
'priority' => \Dot\Log\Logger::WARN,
],
],
],
Expand All @@ -65,7 +65,7 @@ return [
// Warnings and more important messages
'WarningOrHigherWriter' => [
'name' => 'stream',
'priority' => \Dot\Log\Manager\Logger::ALERT,
'priority' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/important_messages.log',
'filters' => [
Expand All @@ -75,7 +75,7 @@ return [
// 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,
'priority' => \Dot\Log\Logger::WARN,
],
],
],
Expand Down
2 changes: 0 additions & 2 deletions docs/book/v4/overview.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Overview

Robust, composite logger with filtering, formatting, and PSR-3 support.

> dot-log is a wrapper on top of [laminas-log](https://github.com/laminas/laminas-log)
2 changes: 1 addition & 1 deletion docs/book/v4/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Basic usage of the logger is illustrated below.
The messages are written to see which logs are written and which are not written.

```php
use Dot\Log\Manager\Logger;
use Dot\Log\Logger;
```

...
Expand Down
12 changes: 12 additions & 0 deletions docs/book/v5/adding-config-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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 the Application-Specific components, e.g.:
* `\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.

> `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`.
43 changes: 43 additions & 0 deletions docs/book/v5/configuring-writer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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',
'level' => \Dot\Log\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 `level` key does not affect the errors that are written.
It is a way to organize writers.

The `level` key is optional.

The key `stream` is required only if writing into streams/files.
Loading