Skip to content

Commit

Permalink
Allow to use any PSR logger (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jul 12, 2024
1 parent dcf4f66 commit 1129acd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Yii Runner HTTP Change Log

## 2.3.1 under development
## 3.0.0 under development

- no changes in this release.
- Chg #76: Allow to use any PSR logger, `NullLogger` by default (@vjik)

## 2.3.0 March 10, 2024

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
"php": "^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0|^2.0 ",
"psr/log": "^3.0",
"yiisoft/config": "^1.1",
"yiisoft/definitions": "^1.0|^2.0|^3.0",
"yiisoft/di": "^1.0",
"yiisoft/error-handler": "^3.0",
"yiisoft/friendly-exception": "^1.1",
"yiisoft/http": "^1.2",
"yiisoft/log": "^2.0",
"yiisoft/log-target-file": "^3.0",
"yiisoft/yii-http": "^1.0",
"yiisoft/yii-runner": "^2.2"
},
Expand Down
11 changes: 7 additions & 4 deletions src/HttpApplicationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Throwable;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
Expand All @@ -18,8 +20,6 @@
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
use Yiisoft\ErrorHandler\Renderer\HtmlRenderer;
use Yiisoft\Http\Method;
use Yiisoft\Log\Logger;
use Yiisoft\Log\Target\File\FileTarget;
use Yiisoft\Yii\Http\Application;
use Yiisoft\Yii\Http\Handler\ThrowableHandler;
use Yiisoft\Yii\Runner\ApplicationRunner;
Expand Down Expand Up @@ -77,6 +77,7 @@ public function __construct(
string $configDirectory = 'config',
string $vendorDirectory = 'vendor',
string $configMergePlanFile = '.merge-plan.php',
private ?LoggerInterface $logger = null,
) {
parent::__construct(
$rootPath,
Expand Down Expand Up @@ -174,8 +175,10 @@ private function createTemporaryErrorHandler(): ErrorHandler
return $this->temporaryErrorHandler;
}

$logger = new Logger([new FileTarget("$this->rootPath/runtime/logs/app.log")]);
return new ErrorHandler($logger, new HtmlRenderer());
return new ErrorHandler(
$this->logger ?? new NullLogger(),
new HtmlRenderer(),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/HttpApplicationRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testRunWithFailureDuringProcess(): void
{
$runner = $this->runner->withContainer($this->createContainer(true));

$this->expectOutputRegex("/^Exception with message 'Failure'/");
$this->expectOutputRegex('/^Exception with message "Failure"/');

$runner->run();
}
Expand Down

0 comments on commit 1129acd

Please sign in to comment.