Skip to content

Commit

Permalink
Doplněn procesor na změnu kanálu z kontextu
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanPala committed Feb 26, 2019
1 parent 0ca0217 commit 5a2d12c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/DI/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ public function loadConfiguration()
->setFactory(\Pd\MonologModule\ChannelLoggerFactory::class)
;

$containerBuilder
->addDefinition($this->prefix('contextChannelProcess'))
->setType(\Pd\MonologModule\Processors\ContextChannelProcessor::class)
->setFactory(\Pd\MonologModule\Processors\ContextChannelProcessor::class)
;

$containerBuilder
->addDefinition($this->prefix('logger'))
->setType(\Monolog\Logger::class)
->setFactory(\Monolog\Logger::class, ['name' => $config['name']])
->addSetup(new \Nette\DI\Statement('$service->pushProcessor(?)', ['@' . \Pd\MonologModule\Processors\ContextChannelProcessor::class]))
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/DayFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle(array $record): bool
$record['filename'] = \strtolower($record['level_name']);
} else {
$this->setFormatter($this->priorityFormatter);
$record['filename'] = $record['channel'];
$record['filename'] = \strtolower($record['channel']);
}

return parent::handle($record);
Expand Down
18 changes: 18 additions & 0 deletions src/Processors/ContextChannelProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Pd\MonologModule\Processors;

final class ContextChannelProcessor
{

public function __invoke($record)
{
if (isset($record['context']['channel'])) {
$record['channel'] = $record['context']['channel'];
unset($record['context']['channel']);
}

return $record;
}

}

0 comments on commit 5a2d12c

Please sign in to comment.