Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added channels to configurations #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ $this->logger->channel('emails');
```

it won't work!

Channels in configuration
-------------------------

```neon
monolog:
channels:
- presenters

services:
front.presenters.homepage:
factory: App\Presenters\HomepagePresenter
arguments:
- @monolog.logger.presenters
```
13 changes: 13 additions & 0 deletions src/DI/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Kdyby\Monolog\DI;

use Kdyby\Monolog\CustomChannel;
use Kdyby\Monolog\Handler\FallbackNetteHandler;
use Kdyby\Monolog\Logger as KdybyLogger;
use Kdyby\Monolog\Processor\PriorityProcessor;
Expand Down Expand Up @@ -51,6 +52,7 @@ class MonologExtension extends \Nette\DI\CompilerExtension
'usePriorityProcessor' => TRUE,
// 'registerFallback' => TRUE,
'accessPriority' => ILogger::INFO,
'channels' => [],
];

public function loadConfiguration()
Expand Down Expand Up @@ -99,6 +101,7 @@ public function loadConfiguration()

$this->loadHandlers($config);
$this->loadProcessors($config);
$this->loadChannels($config);
}

protected function loadHandlers(array $config)
Expand Down Expand Up @@ -156,6 +159,16 @@ protected function loadProcessors(array $config)
}
}

protected function loadChannels(array $config): void
{
$builder = $this->getContainerBuilder();

foreach ($config['channels'] as $channel) {
$builder->addDefinition($this->prefix('logger.' . $channel))
->setFactory(CustomChannel::class, [$channel, $this->prefix('@logger')]);
}
}

public function beforeCompile()
{
$builder = $this->getContainerBuilder();
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/MonologAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function log($originalMessage, $priority = self::INFO)
}

/**
* @param string $priority
* @param mixed $priority
*
* @return int
*/
Expand Down