Exemplo n.º 1
0
 /**
  * ShellMessagesHandler constructor.
  * @param JupyterBroker $broker
  * @param SocketWrapper $iopubSocket
  * @param SocketWrapper $shellSocket
  * @param Logger $logger
  */
 public function __construct(JupyterBroker $broker, SocketWrapper $iopubSocket, SocketWrapper $shellSocket, Logger $logger)
 {
     $this->shellSoul = new Shell();
     $this->executeAction = new ExecuteAction($broker, $iopubSocket, $shellSocket, $this->shellSoul);
     $this->historyAction = new HistoryAction($broker, $shellSocket);
     $this->kernelInfoAction = new KernelInfoAction($broker, $shellSocket, $iopubSocket);
     $this->shutdownAction = new ShutdownAction($broker, $shellSocket);
     $this->logger = $logger;
     $broker->send($iopubSocket, 'status', ['execution_state' => 'starting'], []);
     $this->shellSoul->setOutput(new KernelOutput($this->executeAction, $this->logger->withName('KernelOutput')));
 }
Exemplo n.º 2
0
 /**
  *
  */
 private function registerHandlers()
 {
     $this->hbSocket->on('error', new HbErrorHandler($this->logger->withName('HbErrorHandler')));
     $this->hbSocket->on('messages', new HbMessagesHandler($this->logger->withName('HbMessagesHandler')));
     $this->iopubSocket->on('messages', new IOPubMessagesHandler($this->logger->withName('IOPubMessagesHandler')));
     $this->shellSocket->on('messages', new ShellMessagesHandler($this->broker, $this->iopubSocket, $this->shellSocket, $this->logger->withName('ShellMessagesHandler')));
 }
Exemplo n.º 3
0
 /**
  * @covers Monolog\Logger::withName
  */
 public function testWithName()
 {
     $first = new Logger('first', array($handler = new TestHandler()));
     $second = $first->withName('second');
     $this->assertSame('first', $first->getName());
     $this->assertSame('second', $second->getName());
     $this->assertSame($handler, $second->popHandler());
 }
Exemplo n.º 4
0
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
use Litipk\JupyterPHP\System\System;
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
use Monolog\Handler\FingersCrossedHandler;
use Monolog\Handler\GroupHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogHandler;
use Monolog\Logger;
use Ramsey\Uuid\Uuid;
$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 GroupHandler([new SyslogHandler('jupyter-php'), new StreamHandler('php://stderr')]), $loggerActivationStrategy, 128));
    }
} else {
    $system->ensurePath($system->getAppDataDirectory() . '/logs');
    $logger->pushHandler(new FingersCrossedHandler(new GroupHandler([new RotatingFileHandler($system->getAppDataDirectory() . '/logs/error.log', 7), new StreamHandler('php://stderr')]), $loggerActivationStrategy, 128));
}
try {
    // Obtain settings
    $connectionSettings = ConnectionSettings::get();
    $connUris = ConnectionSettings::getConnectionUris($connectionSettings);
    $kernelCore = new KernelCore(new JupyterBroker($connectionSettings['key'], $connectionSettings['signature_scheme'], Uuid::uuid4(), $logger->withName('JupyterBroker')), $connUris, $logger->withName('KernelCore'));
    $kernelCore->run();
} catch (\Exception $e) {
    $logger->error('Unexpected error', ['exception' => $e]);
}