Skip to content

Commit

Permalink
Migrate Zend to Laminas, Expressive to Mezzio
Browse files Browse the repository at this point in the history
  • Loading branch information
costin committed Jan 30, 2020
1 parent 65faf7b commit a1535f3
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 77 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 2.0.0 - 2020-01-30

### Changed
* Laminas and Mezzio migration.

### Added
* Nothing

### Deprecated
* Nothing

### Removed
* Support

### Fixed
* Nothing


## 1.1.2 - 2018-11-13

### Changed
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ DotKernel log component extending and customizing
* Open the `Dot\Log\ConfigProvider`
* In the dependencies section you will see an absctract factory (LoggerAbstractServiceFactory::class)
* This class responds to "selectors" instead of class names
- Instead of requesting the `Zend\Log\Logger::class` from the container, dot-log.my_logger should be requested (or just `my_logger` if using zend-log)
- Instead of requesting the `Laminas\Log\Logger::class` from the container, dot-log.my_logger should be requested (or just `my_logger` if using laminas-log)

## Configuring the writer(s)
Loggers must have at least one writer.

A writer is an object that inherits from `Zend\Log\Writer\AbstractWriter`. A writer's responsibility is to record log data to a storage backend. (from zend-log's writer documentation)
A writer is an object that inherits from `Laminas\Log\Writer\AbstractWriter`. A writer's responsibility is to record log data to a storage backend. (from laminas-log's writer documentation)



Expand All @@ -32,7 +32,7 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Zend\Log\Logger::ALERT, // this is equal to 1
'priority' => \Laminas\Log\Logger::ALERT, // this is equal to 1
'options' => [
'stream' => __DIR__.'/../../data/logs/dk.log',
],
Expand Down Expand Up @@ -64,7 +64,7 @@ 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 Zend Log is not fully compatible with PSR-3, it provides a way to log all of these message types.
Although the plain Logger in Laminas 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:
Expand All @@ -82,15 +82,15 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Zend\Log\Logger::ALERT,
'priority' => \Laminas\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__.'/../../data/logs/dk.log',
'filters' => [
'allMessages' => [
'name' => 'priority',
'options' => [
'operator' => '>=',
'priority' => \Zend\Log\Logger::EMERG,
'priority' => \Laminas\Log\Logger::EMERG,
]
],
],
Expand All @@ -99,15 +99,15 @@ return [
// Only warnings
'OnlyWarningsWriter' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::ALERT,
'priority' => \Laminas\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__.'/../../data/logs/warnings_only.log',
'filters' => [
'warningOnly' => [
'name' => 'priority',
'options' => [
'operator' => '==',
'priority' => \Zend\Log\Logger::WARN,
'priority' => \Laminas\Log\Logger::WARN,
],
],
],
Expand All @@ -116,7 +116,7 @@ return [
// Warnings and more important messages
'WarningOrHigherWriter' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::ALERT,
'priority' => \Laminas\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__.'/../../data/logs/important_messages.log',
'filters' => [
Expand All @@ -126,7 +126,7 @@ return [
// note, the smaller the priority, the more important is the message
// 0 - emergency, 1 - alert, 2- error, 3 - warn. .etc
'operator' => '<=',
'priority' => \Zend\Log\Logger::WARN,
'priority' => \Laminas\Log\Logger::WARN,
],
],
],
Expand All @@ -149,28 +149,28 @@ It was added opposite to the others just to demonstrate the other operator is al



More examples on filters: https://zendframework.github.io/zend-log/filters/
More examples on filters: https://docs.laminas.dev/laminas-log/filters/

## Formatting Messages

When using `dot-log` or `zend-log`, the logged value is not limited to a string. Arrays can be logged as well.
When using `dot-log` or `laminas-log`, the logged value is not limited to a string. Arrays can be logged as well.

For a better readability, these arrays can be serialized.

Zend Log provides String formatting, XML, JSON and FirePHP formatting.
Laminas Log provides String formatting, XML, JSON and FirePHP formatting.



The formatter accepts following parameters:

name - the formatter class (it must implement Zend\Log\Formatter\FormatterInterface)
name - the formatter class (it must implement Laminas\Log\Formatter\FormatterInterface)
options - options to pass to the formatter constructor if required


The following formats the message as JSON data:

'formatter' => [
'name' => \Zend\Log\Formatter\Json::class,
'name' => \Laminas\Log\Formatter\Json::class,
],


Expand All @@ -193,7 +193,7 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'FileWriter',
'priority' => \Zend\Log\Logger::ALERT,
'priority' => \Laminas\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__.'/../../data/logs/dk.log',
// explicitly log all messages
Expand All @@ -202,12 +202,12 @@ return [
'name' => 'priority',
'options' => [
'operator' => '>=',
'priority' => \Zend\Log\Logger::EMERG,
'priority' => \Laminas\Log\Logger::EMERG,
],
],
],
'formatter' => [
'name' => \Zend\Log\Formatter\Json::class,
'name' => \Laminas\Log\Formatter\Json::class,
],
],
],
Expand All @@ -223,7 +223,7 @@ Basic usage of the logger is illustraded below.

The messages are written to see which logs are written and which are not written.
```php
use Zend\Log\Logger;
use Laminas\Log\Logger;
```
...
```php
Expand All @@ -242,9 +242,9 @@ $logger->log(Logger::NOTICE, 'NOTICE from log()');
```

Sources:
* https://zendframework.github.io/zend-log/
* https://zendframework.github.io/zend-log/writers/
* https://zendframework.github.io/zend-log/filters/
* https://docs.laminas.dev/laminas-log/
* https://docs.laminas.dev/laminas-log/writers/
* https://docs.laminas.dev/laminas-log/filters/

Extracted from [this article](https://www.dotkernel.com/dotkernel/logging-with-dot-log-in-zend-expressive-and-dotkernel)
Extracted from [this article](https://www.dotkernel.com/dotkernel/logging-with-dot-log-in-mezzio-and-dotkernel)

74 changes: 37 additions & 37 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
{
"name": "dotkernel/dot-log",
"type": "library",
"description": "DotKernel log component extending and customizing zend-log",
"license": "MIT",
"authors": [
{
"name": "DotKernel Team",
"email": "[email protected]"
"name": "dotkernel/dot-log",
"type": "library",
"description": "DotKernel log component extending and customizing laminas-log",
"license": "MIT",
"authors": [
{
"name": "DotKernel Team",
"email": "[email protected]"
}
],
"require": {
"php": "^7.2",
"psr/http-message": "^1.0",
"laminas/laminas-servicemanager": "^3.3.0",
"laminas/laminas-log": "^2.9.0",
"laminas/laminas-dependency-plugin": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "^2.3",
"dotkernel/dot-mail": "^2.0"
},
"autoload": {
"psr-4": {
"Dot\\Log\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DotTest\\Log\\": "test/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev",
"dev-develop": "2.1-dev"
}
}
],
"require": {
"php": "^7.1",
"psr/http-message": "^1.0",
"zendframework/zend-servicemanager": "^3.3.0",
"zendframework/zend-log": "^2.9.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "^2.3",

"dotkernel/dot-mail": "^1.0"
},
"autoload": {
"psr-4": {
"Dot\\Log\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DotTest\\Log\\": "test/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev",
"dev-develop": "1.2-dev"
}
}
}
6 changes: 3 additions & 3 deletions log.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return [
'stream_logger' => [
'writers' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::DEBUG,
'priority' => \Laminas\Log\Logger::DEBUG,
'options' => [
'stream' => 'php://output',
'formatter' => [
Expand All @@ -29,7 +29,7 @@ return [
'db_logger' => [
'writers' => [
'name' => 'db',
'priority' => \Zend\Log\Logger::INFO,
'priority' => \Laminas\Log\Logger::INFO,
'options' => [
//service name of the database adapter
'db' => 'database',
Expand Down Expand Up @@ -62,7 +62,7 @@ return [
'mail_logger' => [
'writers' => [
'name' => 'mail',
'priority' => \Zend\Log\Logger::ERR,
'priority' => \Laminas\Log\Logger::ERR,
'options' => [
'mail_service' => 'dot-mail.mail-service.service_name',

Expand Down
12 changes: 6 additions & 6 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
use Dot\Log\Factory\LoggerAbstractServiceFactory;
use Dot\Log\Factory\ProcessorPluginManagerFactory;
use Dot\Log\Factory\WriterPluginManagerFactory;
use Zend\Log\FilterPluginManager;
use Zend\Log\FormatterPluginManager;
use Zend\Log\Logger;
use Zend\Log\LoggerServiceFactory;
use Zend\Log\ProcessorPluginManager;
use Zend\Log\WriterPluginManager;
use Laminas\Log\FilterPluginManager;
use Laminas\Log\FormatterPluginManager;
use Laminas\Log\Logger;
use Laminas\Log\LoggerServiceFactory;
use Laminas\Log\ProcessorPluginManager;
use Laminas\Log\WriterPluginManager;

/**
* Class ConfigProvider
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FilterPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Dot\Log\Factory;

use Psr\Container\ContainerInterface;
use Zend\Log\FilterPluginManager;
use Laminas\Log\FilterPluginManager;

/**
* Class FilterPluginManagerFactory
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FormatterPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Dot\Log\Factory;

use Psr\Container\ContainerInterface;
use Zend\Log\FormatterPluginManager;
use Laminas\Log\FormatterPluginManager;

/**
* Class FormatterPluginManagerFactory
Expand Down
8 changes: 4 additions & 4 deletions src/Factory/LoggerAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

use Dot\Mail\Service\MailServiceInterface;
use Interop\Container\ContainerInterface;
use Zend\Log\Writer\Mail;
use Laminas\Log\Writer\Mail;

/**
* Class LoggerAbstractServiceFactory
* @package Dot\Log
*/
class LoggerAbstractServiceFactory extends \Zend\Log\LoggerAbstractServiceFactory
class LoggerAbstractServiceFactory extends \Laminas\Log\LoggerAbstractServiceFactory
{
const PREFIX = 'dot-log';

Expand Down Expand Up @@ -49,7 +49,7 @@ public function canCreate(ContainerInterface $container, $requestedName)
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return object|\Zend\Log\Logger
* @return object|\Laminas\Log\Logger
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
Expand Down Expand Up @@ -91,7 +91,7 @@ protected function processConfig(&$config, ContainerInterface $services)
if (isset($writerConfig['name'])
&& ('mail' === $writerConfig['name']
|| Mail::class === $writerConfig['name']
|| 'zendlogwritermail' === $writerConfig['name']
|| 'laminaslogwritermail' === $writerConfig['name']
)
&& isset($writerConfig['options']['mail_service'])
&& is_string($writerConfig['options']['mail_service'])
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/ProcessorPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Dot\Log\Factory;

use Psr\Container\ContainerInterface;
use Zend\Log\ProcessorPluginManager;
use Laminas\Log\ProcessorPluginManager;

/**
* Class ProcessorPluginManagerFactory
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/WriterPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Dot\Log\Factory;

use Psr\Container\ContainerInterface;
use Zend\Log\WriterPluginManager;
use Laminas\Log\WriterPluginManager;

/**
* Class WriterPluginManagerFactory
Expand Down

0 comments on commit a1535f3

Please sign in to comment.