-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
314 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
language: php | ||
php: | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
|
||
script: | ||
- composer validate | ||
- vendor/bin/phpcs src/ --standard=vendor/pd/coding-standard/src/PeckaCodingStandard/ruleset.xml | ||
- vendor/bin/phpcs src/ --standard=vendor/pd/coding-standard/src/PeckaCodingStandardStrict/ruleset.xml | ||
- vendor/bin/phpstan analyse src/ --level 2 --no-progress | ||
|
||
before_script: | ||
- composer install --no-interaction --prefer-dist | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\MonologModule; | ||
|
||
final class ChannelLogger implements \Psr\Log\LoggerInterface | ||
{ | ||
|
||
/** | ||
* @var \Psr\Log\LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $channel; | ||
|
||
|
||
public function __construct(\Psr\Log\LoggerInterface $logger, string $channel) | ||
{ | ||
$this->logger = $logger; | ||
$this->channel = $channel; | ||
} | ||
|
||
|
||
private function getContext(array $context): array | ||
{ | ||
return ['channel' => $this->channel] + $context; | ||
} | ||
|
||
|
||
public function emergency($message, array $context = []) | ||
{ | ||
$this->logger->emergency($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function alert($message, array $context = []) | ||
{ | ||
$this->logger->alert($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function critical($message, array $context = []) | ||
{ | ||
$this->logger->critical($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function error($message, array $context = []) | ||
{ | ||
$this->logger->error($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function warning($message, array $context = []) | ||
{ | ||
$this->logger->warning($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function notice($message, array $context = []) | ||
{ | ||
$this->logger->notice($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function info($message, array $context = []) | ||
{ | ||
$this->logger->info($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function debug($message, array $context = []) | ||
{ | ||
$this->logger->debug($message, $this->getContext($context)); | ||
} | ||
|
||
|
||
public function log($level, $message, array $context = []) | ||
{ | ||
$this->logger->log($message, $this->getContext($context)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\MonologModule; | ||
|
||
final class ChannelLoggerFactory | ||
{ | ||
|
||
/** | ||
* @var \Psr\Log\LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
|
||
public function __construct(\Psr\Log\LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
|
||
public function create(string $channel): \Psr\Log\LoggerInterface | ||
{ | ||
$logger = new ChannelLogger($this->logger, $channel); | ||
|
||
return $logger; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,42 @@ | ||
<?php | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\MonologModule\DI; | ||
|
||
use Kdyby; | ||
use Nette; | ||
use Pd; | ||
|
||
|
||
class Extension extends Nette\DI\CompilerExtension | ||
final class Extension extends \Nette\DI\CompilerExtension | ||
{ | ||
|
||
private $defaults = [ | ||
'allowedTypes' => [ | ||
], | ||
'name' => '', | ||
]; | ||
|
||
|
||
public function beforeCompile() | ||
public function loadConfiguration() | ||
{ | ||
parent::loadConfiguration(); | ||
|
||
$containerBuilder = $this->getContainerBuilder(); | ||
|
||
$config = $this->validateConfig($this->defaults); | ||
|
||
$presenterBridge = $containerBuilder | ||
->addDefinition($this->prefix('presenterBridge')) | ||
->setClass(PresenterBridge::class, [$config['allowedTypes']]) | ||
$containerBuilder | ||
->addDefinition($this->prefix('channelLoggerFactory')) | ||
->setFactory(\Pd\MonologModule\ChannelLoggerFactory::class) | ||
; | ||
|
||
$application = $containerBuilder->getDefinition($containerBuilder->getByType(Nette\Application\Application::class)); | ||
$application->addSetup('?->onPresenter[] = ?', ['@self', [$presenterBridge, 'onPresenter']]); | ||
$containerBuilder | ||
->addDefinition($this->prefix('logger')) | ||
->setType(\Monolog\Logger::class) | ||
->setFactory(\Monolog\Logger::class, ['name' => $config['name']]) | ||
; | ||
} | ||
|
||
|
||
public function setCompiler(Nette\DI\Compiler $compiler, $name) | ||
public function afterCompile(\Nette\PhpGenerator\ClassType $class) | ||
{ | ||
$parent = parent::setCompiler($compiler, $name); | ||
|
||
$monologExtension = new Kdyby\Monolog\DI\MonologExtension(); | ||
$compiler->addExtension('monolog', $monologExtension); | ||
$initialize = $class->getMethod('initialize'); | ||
|
||
return $parent; | ||
$initialize->addBody('$tracyLogger = new \Tracy\Bridges\Psr\PsrToTracyLoggerAdapter($this->getByType(\Psr\Log\LoggerInterface::class));'); | ||
$initialize->addBody('\Tracy\Debugger::setLogger($tracyLogger);'); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\MonologModule\Handlers; | ||
|
||
final class BlueScreenHandler extends \Monolog\Handler\AbstractProcessingHandler | ||
{ | ||
|
||
/** | ||
* @var \Tracy\BlueScreen | ||
*/ | ||
private $blueScreenRenderer; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $logDirectory; | ||
|
||
|
||
public function __construct(string $logDir, $level = \Monolog\Logger::DEBUG) | ||
{ | ||
parent::__construct($level, TRUE); | ||
|
||
$this->blueScreenRenderer = new \Tracy\BlueScreen(); | ||
$this->logDirectory = $logDir; | ||
} | ||
|
||
|
||
private function getLogDirectory(\DateTimeInterface $dateTime) | ||
{ | ||
$pathParts = [ | ||
$this->logDirectory, | ||
'exception', | ||
$dateTime->format('Y-m'), | ||
]; | ||
|
||
return \implode('/', $pathParts); | ||
} | ||
|
||
|
||
protected function write(array $record): void | ||
{ | ||
if ( ! isset($record['context']['exception'])) { | ||
return; | ||
} | ||
|
||
$extensionLogger = new \Tracy\Logger($this->getLogDirectory($record['datetime'])); | ||
|
||
$exception = $record['context']['exception']; | ||
$exceptionFile = $extensionLogger->getExceptionFile($exception); | ||
|
||
$this->blueScreenRenderer->renderToFile($exception, $exceptionFile); | ||
} | ||
|
||
} |
Oops, something went wrong.