Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Minor code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
castarco committed Mar 27, 2016
1 parent 3135a1e commit bdef2bf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/JupyterBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function send(
);

if (null !== $this->logger) {
$this->logger->debug('Sent message', ['processId' => posix_getpid(), 'message/' => $finalMsg]);
$this->logger->debug('Sent message', ['processId' => posix_getpid(), 'message' => $finalMsg]);
}

$stream->send($finalMsg);
Expand Down
12 changes: 10 additions & 2 deletions src/KernelOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(ExecuteAction $executeAction, LoggerInterface $logge
*/
public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
{
$this->logger->debug('Write operation inside KernelOutput');

$types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN;
$type = $types & $options ?: self::OUTPUT_NORMAL;

Expand Down Expand Up @@ -201,6 +199,16 @@ private function initFormatters()
$formatter->setStyle('urgent', new OutputFormatterStyle('red'));
$formatter->setStyle('hidden', new OutputFormatterStyle('white'));

// Visibility
$formatter->setStyle('public', new OutputFormatterStyle(null, null, array('bold')));
$formatter->setStyle('protected', new OutputFormatterStyle('yellow'));
$formatter->setStyle('private', new OutputFormatterStyle('red'));
$formatter->setStyle('global', new OutputFormatterStyle('cyan', null, array('bold')));
$formatter->setStyle('const', new OutputFormatterStyle('cyan'));
$formatter->setStyle('class', new OutputFormatterStyle('blue', null, array('underscore')));
$formatter->setStyle('function', new OutputFormatterStyle(null));
$formatter->setStyle('default', new OutputFormatterStyle(null));

// Types
$formatter->setStyle('number', new OutputFormatterStyle('magenta'));
$formatter->setStyle('string', new OutputFormatterStyle('green'));
Expand Down
28 changes: 28 additions & 0 deletions src/LoggerSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php


namespace Litipk\JupyterPHP;


use Monolog\Logger;


final class LoggerSettings
{
/**
* @return int
*/
public static function getCrossFingersLevel()
{
global $argv;
if (!isset($argv) || empty($argv)) {
$argv = $_SERVER['argv'];
}

if (is_array($argv) && count($argv) > 2) {
return ('debug' === trim(strtolower($argv[2]))) ? Logger::DEBUG : Logger::WARNING;
} else {
return Logger::WARNING;
}
}
}
12 changes: 9 additions & 3 deletions src/kernel.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bn/env php
#!/usr/bin/env php
<?php


Expand All @@ -20,15 +20,21 @@
$system = System::getSystem();
$logger = new Logger('kernel');

$loggerActivationStrategy = new ErrorLevelActivationStrategy(LoggerSettings::getCrossFingersLevel());

if ('root' === $system->getCurrentUser()) {
if (System::OS_LINUX === $system->getOperativeSystem()) {
$logger->pushHandler(new FingersCrossedHandler(new SyslogHandler('jupyter-php'), null, 128));
$logger->pushHandler(new FingersCrossedHandler(
new SyslogHandler('jupyter-php'),
$loggerActivationStrategy,
128
));
}
} else {
$system->ensurePath($system->getAppDataDirectory().'/logs');
$logger->pushHandler(new FingersCrossedHandler(
new RotatingFileHandler($system->getAppDataDirectory().'/logs/error.log', 7),
new ErrorLevelActivationStrategy(Logger::DEBUG),
$loggerActivationStrategy,
128
));
}
Expand Down

0 comments on commit bdef2bf

Please sign in to comment.