Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merging develop to master in preparation for 2.12.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 27, 2019
2 parents 998fede + 7b85b58 commit e5ec088
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 28 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.11.1 - TBD
## 2.12.0 - 2019-12-27

### Added

- Nothing.
- [#99](https://github.com/zendframework/zend-log/pull/99) adds `Zend\Log\PsrLoggerAbstractAdapterFactory`, which will create instances of `PsrLoggerAdapter`. Usage is exactly like with `Zend\Log\LoggerAbstractServiceFactory`, with the exception that it looks under the `psr_log` configuration key instead of the `log` key for logger configuration.

### Changed

- Nothing.
- [#100](https://github.com/zendframework/zend-log/pull/100) updates the psr/log constraint to 1.1.2, removing the need for an extra autoloader in this package.

### Deprecated

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"require": {
"php": "^5.6 || ^7.0",
"psr/log": "^1.0",
"psr/log": "^1.1.2",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
Expand Down Expand Up @@ -53,7 +53,6 @@
"ZendTest\\Log\\": "test/"
},
"files": [
"test/autoload.php",
"test/Writer/TestAsset/chmod.php"
]
},
Expand All @@ -62,8 +61,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.11.x-dev",
"dev-develop": "2.12.x-dev"
"dev-master": "2.12.x-dev",
"dev-develop": "2.13.x-dev"
},
"zf": {
"component": "Zend\\Log",
Expand Down
15 changes: 8 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions docs/book/psr3.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ $logger->addProcessor(new Zend\Log\Processor\PsrPlaceholder);
$logger->info('User with email {email} registered', ['email' => 'user@example.org']);
// logs message 'User with email user@example.org registered'
```

## Usage with zend-servicemanager

For usage with zend-servicemanager, read the [`PsrLoggerAbstractServiceFactory`
documentation](service-manager.md#psrloggerabstractservicefactory).
69 changes: 69 additions & 0 deletions docs/book/service-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,75 @@ Because the main filter is `Priority`, it can be set directly too:
];
```

## PsrLoggerAbstractServiceFactory

As with the [`LoggerAbstractServiceFactory` above](#loggerabstractservicefactory),
you can use `PsrLoggerAbstractServiceFactory` to create [PSR-3-conforming
logger instances](psr3.md). Register it as an abstract factory in your
configuration; as an example:

```php
// module.config.php

use Zend\Log\PsrLoggerAbstractServiceFactory;

return [
'service_manager' => [
'abstract_factories' => [
PsrLoggerAbstractServiceFactory::class,
],
],
];
```

Additionally, instead of using the `log` configuration key, you will use the key
`psr_log`:

```php
// module.config.php

use Zend\Log\Formatter\Simple;
use Zend\Log\Logger;
use Zend\Log\Processor\RequestId;

return [
'psr_log' => [ // <-- NOTE: key change!
'MyLogger' => [
'writers' => [
'stream' => [
'name' => 'stream',
'priority' => 1,
'options' => [
'stream' => 'php://output',
'formatter' => [
'name' => Simple::class,
'options' => [
'format' => '%timestamp% %priorityName% (%priority%): %message% %extra%',
'dateTimeFormat' => 'c',
],
],
'filters' => [
'priority' => [
'name' => 'priority',
'options' => [
'operator' => '<=',
'priority' => Logger::INFO,
],
],
],
],
],
],
'processors' => [
'requestid' => [
'name' => RequestId::class,
],
],
],
],
];
```

## Custom Writers, Formatters, Filters, and Processors

In the `LoggerAbstractServiceFactory` example above, a custom formatter (called
Expand Down
1 change: 1 addition & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function getDependencyConfig()
return [
'abstract_factories' => [
LoggerAbstractServiceFactory::class,
PsrLoggerAbstractAdapterFactory::class,
],
'factories' => [
Logger::class => LoggerServiceFactory::class,
Expand Down
34 changes: 34 additions & 0 deletions src/PsrLoggerAbstractAdapterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-log for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Log;

use Interop\Container\ContainerInterface;

/**
* PSR Logger abstract service factory.
*
* Allow to configure multiple loggers for application.
*/
class PsrLoggerAbstractAdapterFactory extends LoggerAbstractServiceFactory
{
/**
* Configuration key holding logger configuration
*
* @var string
*/
protected $configKey = 'psr_log';

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$logger = parent::__invoke($container, $requestedName, $options);

return new PsrLoggerAdapter($logger);
}
}
88 changes: 88 additions & 0 deletions test/PsrLoggerAbstractAdapterFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zend-log for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Log;

use PHPUnit\Framework\TestCase;
use Zend\Log\PsrLoggerAbstractAdapterFactory;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\ServiceManager;

class PsrLoggerAbstractAdapterFactoryTest extends TestCase
{
/**
* @var \Zend\ServiceManager\ServiceLocatorInterface
*/
protected $serviceManager;

/**
* Set up LoggerAbstractServiceFactory and loggers configuration.
*/
protected function setUp()
{
$this->serviceManager = new ServiceManager();
$config = new Config([
'abstract_factories' => [PsrLoggerAbstractAdapterFactory::class],
'services' => [
'config' => [
'psr_log' => [
'Application\Frontend' => [],
'Application\Backend' => [],
],
],
],
]);
$config->configureServiceManager($this->serviceManager);
}

/**
* @return array
*/
public function providerValidLoggerService()
{
return [
['Application\Frontend'],
['Application\Backend'],
];
}

/**
* @return array
*/
public function providerInvalidLoggerService()
{
return [
['Logger\Application\Unknown'],
['Logger\Application\Frontend'],
['Application\Backend\Logger'],
];
}

/**
* @param string $service
* @dataProvider providerValidLoggerService
*/
public function testValidLoggerService($service)
{
$actual = $this->serviceManager->get($service);
$this->assertInstanceOf('Zend\Log\PsrLoggerAdapter', $actual);
}

/**
* @dataProvider providerInvalidLoggerService
*
* @param string $service
*/
public function testInvalidLoggerService($service)
{
$this->expectException(ServiceNotFoundException::class);
$this->serviceManager->get($service);
}
}
14 changes: 0 additions & 14 deletions test/autoload.php

This file was deleted.

0 comments on commit e5ec088

Please sign in to comment.