Skip to content

Commit

Permalink
add default logger
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Aug 10, 2021
1 parent bc7517c commit a1f489d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@

declare(strict_types=1);

use Psr\Log\LogLevel;

return [
'log' => [
'path' => [
'default' => 'php-profiler.log',
],
'level' => LogLevel::INFO,
],
'paths' => [
'templates' => __DIR__ . '/../resources/templates',
],
Expand Down
14 changes: 13 additions & 1 deletion config/di.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

declare(strict_types=1);

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Noodlehaus\Config;
use PhpProfiler\Inspector\Daemon\Reader\Worker\PhpReaderTraceLoop;
use PhpProfiler\Inspector\Daemon\Reader\Worker\PhpReaderTraceLoopInterface;
Expand All @@ -29,7 +31,7 @@
use PhpProfiler\Lib\Process\MemoryReader\MemoryReaderInterface;
use PhpProfiler\Lib\Process\Search\ProcessSearcher;
use PhpProfiler\Lib\Process\Search\ProcessSearcherInterface;

use Psr\Log\LoggerInterface;
use function DI\autowire;

return [
Expand All @@ -48,4 +50,14 @@
ProcessSearcherInterface::class => autowire(ProcessSearcher::class),
Config::class => fn () => Config::load(__DIR__ . '/config.php'),
TemplatePathResolverInterface::class => autowire(TemplatePathResolver::class),
LoggerInterface::class => function (Config $config) {
$logger = new Logger('default');
$logger->pushHandler(
new StreamHandler(
$config->get('log.path.default'),
Logger::toMonologLevel($config->get('log.level'))
)
);
return $logger;
}
];

0 comments on commit a1f489d

Please sign in to comment.