Skip to content

Commit

Permalink
Merge pull request dotkernel#37 from dotkernel/issue-36
Browse files Browse the repository at this point in the history
Issue dotkernel#36: Upgraded `dot-log` to `4.x`. Prepare package for version `4.x`.
  • Loading branch information
alexmerlin authored Aug 30, 2024
2 parents 48e8c89 + a0929b9 commit 0c46abe
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 25 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# dot-errorhandler

Logging Error Handler for DotKernel
Error Logging Handler for DotKernel

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

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

[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/3.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)

[![SymfonyInsight](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454/big.svg)](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454)

Expand Down Expand Up @@ -78,7 +78,6 @@ use Dot\ErrorHandler\ErrorHandlerInterface;
use Custom\MyErrorHandler;
use Custom\MyErrorHandlerFactory;


return [
'dependencies' => [
'factories' => [
Expand Down
10 changes: 4 additions & 6 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

## Supported Versions


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

| <= 2.x | :x: | |

## Reporting Potential Security Issues

Expand All @@ -27,7 +26,6 @@ release prior to any public exposure; this helps protect the project's
users, and provides them with a chance to upgrade and/or update in order to
protect their applications.


## Policy

If we verify a reported security vulnerability, our policy is:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"require": {
"php": "~8.2.0 || ~8.3.0",
"dotkernel/dot-log": "^3.4",
"dotkernel/dot-log": "^4.0.2",
"laminas/laminas-diactoros": "^3.3",
"laminas/laminas-stratigility": "^3.11",
"mezzio/mezzio": "^3.19",
Expand Down
9 changes: 3 additions & 6 deletions config/log.global.php.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php

use Laminas\Log\Formatter\Json;
use Laminas\Log\Logger;

return [
'dot_log' => [
'loggers' => [
'default_logger' => [
'writers' => [
'FileWriter' => [
'name' => 'stream',
'priority' => Logger::ALERT,
'priority' => \Dot\Log\Logger::ALERT,
'options' => [
'stream' => __DIR__ . '/../../log/error-log-{Y}-{m}-{d}.log',
// explicitly log all messages
Expand All @@ -19,12 +16,12 @@ return [
'name' => 'priority',
'options' => [
'operator' => '>=',
'priority' => Logger::EMERG,
'priority' => \Dot\Log\Logger::EMERG,
],
],
],
'formatter' => [
'name' => Json::class,
'name' => \Dot\Log\Formatter\Json::class,
],
],
],
Expand Down
76 changes: 76 additions & 0 deletions docs/book/v4/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Configuration

Register `dot-errorhandler` in you project by adding `Dot\ErrorHandler\ConfigProvider::class` to your configuration aggregator (to `config/config.php` for example),
and add `\Dot\ErrorHandler\ErrorHandlerInterface::class` (to `config/pipeline.php` for example) **as the outermost layer of the middleware** to catch all Exceptions

- Configure the error handler as shown below

config/autoload/error-handling.global.php

```php
<?php

use Dot\ErrorHandler\ErrorHandlerInterface;
use Dot\ErrorHandler\LogErrorHandler;
use Dot\ErrorHandler\ErrorHandler;

return [
'dependencies' => [
'aliases' => [
ErrorHandlerInterface::class => LogErrorHandler::class,
]

],
'dot-errorhandler' => [
'loggerEnabled' => true,
'logger' => 'dot-log.default_logger'
]
];
```

A configuration example for the default logger can be found in `config/log.global.php.dist`.

When declaring the `ErrorHandlerInterface` alias you can choose whether to log or not:

- for the simple Zend Expressive handler user `ErrorHandler`
- for logging use `LogErrorHandler`

The class `Dot\ErrorHandler\ErrorHandler` is the same as the Zend Expressive error handling class
the only difference being the removal of the `final` statement for making extension possible.

The class `Dot\ErrorHandler\LogErrorHandler` is `Dot\ErrorHandler\ErrorHandler` with
added logging support.

As a note: both `LogErrorHandler` and `ErrorHandler` have factories declared in the
package's `ConfigProvider`. If you need a custom ErrorHandler it must have a factory
declared in the config, as in the example.

Example:

```php
<?php

use Dot\ErrorHandler\ErrorHandlerInterface;
use Custom\MyErrorHandler;
use Custom\MyErrorHandlerFactory;


return [
'dependencies' => [
'factories' => [
MyErrorHandler::class => MyCustomHandlerFactory::class,
],

'aliases' => [
ErrorHandlerInterface::class => MyErrorHandler::class,
]

],
'dot-errorhandler' => [
'loggerEnabled' => true,
'logger' => 'dot-log.default_logger'
]
];
```

Config examples can be found in this project's `config` directory.
5 changes: 5 additions & 0 deletions docs/book/v4/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Installation

Install `dotkernel/dot-errorhandler` by executing the following Composer command:

composer require dotkernel/dot-errorhandler
6 changes: 6 additions & 0 deletions docs/book/v4/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Overview

`dot-errorhandler` is DotKernel's logging error handler, providing two options:

- `Dot\ErrorHandler\ErrorHandler`, same as the Zend Expressive error handling class with the only difference being the removal of the `final` statement for making extension possible
- `Dot\ErrorHandler\LogErrorHandler` adds logging support to the default `ErrorHandler` class
9 changes: 7 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ docs_dir: docs/book
site_dir: docs/html
extra:
project: Packages
current_version: v3
current_version: v4
versions:
- v4
- v3
nav:
- Home: index.md
- v4:
- Overview: v4/overview.md
- Installation: v4/installation.md
- Configuration: v4/configuration.md
- v3:
- Overview: v3/overview.md
- Installation: v3/installation.md
- Configuration: v3/configuration.md
site_name: dot-errorhandler
site_description: "DotKernel's logging error handler"
site_description: "DotKernel's error logging handler"
repo_url: "https://github.com/dotkernel/dot-errorhandler"
plugins:
- search
2 changes: 1 addition & 1 deletion src/LogErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Dot\ErrorHandler;

use Dot\Log\LoggerInterface;
use ErrorException;
use Laminas\Log\LoggerInterface;
use Laminas\Stratigility\Middleware\ErrorResponseGenerator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/LogErrorHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Dot\ErrorHandler;

use Dot\Log\LoggerInterface;
use InvalidArgumentException;
use Laminas\Log\LoggerInterface;
use Mezzio\Middleware\ErrorResponseGenerator;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
Expand Down
6 changes: 3 additions & 3 deletions test/LogErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Dot\ErrorHandler\LogErrorHandler;
use Dot\ErrorHandler\LogErrorHandler as Subject;
use Dot\Log\Formatter\Json;
use Dot\Log\Logger;
use Dot\Log\LoggerInterface;
use ErrorException;
use Laminas\Log\Formatter\Json;
use Laminas\Log\Logger;
use Laminas\Log\LoggerInterface;
use Laminas\Stratigility\Middleware\ErrorResponseGenerator;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
Expand Down

0 comments on commit 0c46abe

Please sign in to comment.