Ejemplo n.º 1
0
 public function testTrigger()
 {
     $log = new \Monolog\Logger('core');
     $handler = new \Monolog\ErrorHandler($log);
     $log->pushHandler(new \Monolog\Handler\StreamHandler((string) (__DIR__ . '/../') . 'error.txt', \Monolog\Logger::WARNING));
     // \Monolog\ErrorHandler::register($log);
     $handler->registerErrorHandler([], false);
     $handler->registerExceptionHandler();
     $handler->registerFatalHandler();
     $log->warning('Foo');
     $log->error('Bar');
 }
Ejemplo n.º 2
0
 protected function loadLog()
 {
     $logConfig = $this->get('config')->get('logger');
     $log = new \Fox\Core\Utils\Log('Fox');
     $levelCode = $log->getLevelCode($logConfig['level']);
     if ($logConfig['isRotate']) {
         $handler = new \Fox\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($logConfig['path'], $logConfig['maxRotateFiles'], $levelCode);
     } else {
         $handler = new \Fox\Core\Utils\Log\Monolog\Handler\StreamHandler($logConfig['path'], $levelCode);
     }
     $log->pushHandler($handler);
     $errorHandler = new \Monolog\ErrorHandler($log);
     $errorHandler->registerExceptionHandler(null, false);
     $errorHandler->registerErrorHandler(array(), false);
     return $log;
 }
Ejemplo n.º 3
0
 /**
  * create php errorhandler, which also logs to php error_log
  *
  * @param Monolog\Logger $app
  */
 private static function registerErrorHandler($app)
 {
     // get base logger
     $logger = clone $app;
     // add extra handler
     $handler = new Monolog\Handler\ErrorLogHandler();
     // set formatter without datetime
     $handler->setFormatter(new Monolog\Formatter\LineFormatter('%channel%.%level_name%: %message% %context% %extra%'));
     $logger->pushHandler($handler);
     // attach php errorhandler to app logger
     Monolog\ErrorHandler::register($logger);
 }
Ejemplo n.º 4
0
 protected function loadLog()
 {
     $config = $this->get('config');
     $path = $config->get('logger.path', 'data/logs/espo.log');
     $rotation = $config->get('logger.rotation', true);
     $log = new \Espo\Core\Utils\Log('Espo');
     $levelCode = $log->getLevelCode($config->get('logger.level', 'WARNING'));
     if ($rotation) {
         $maxFileNumber = $config->get('logger.maxFileNumber', 30);
         $handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($path, $maxFileNumber, $levelCode);
     } else {
         $handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($path, $levelCode);
     }
     $log->pushHandler($handler);
     $errorHandler = new \Monolog\ErrorHandler($log);
     $errorHandler->registerExceptionHandler(null, false);
     $errorHandler->registerErrorHandler(array(), false);
     return $log;
 }
Ejemplo n.º 5
0
<?php

declare (strict_types=1);
// Load autoloader & 3rd party libraries
require_once __DIR__ . '/vendor/autoload.php';
// Disable error messages in output
ini_set('display_errors', 'no');
// Ensure a few local system settings
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
// Setup DiC with Environment config
$environment = (require __DIR__ . '/config/env.php');
$container = new Pimple\Container(require __DIR__ . '/config/' . $environment . '.php');
$container['environment'] = $environment;
// Have Monolog log all PHP errors
Monolog\ErrorHandler::register($container['logger']);
// Register services to DiC
(new Spot\DefaultServiceProvider())->init($container);
(new Spot\Auth\AuthServiceProvider('/auth'))->init($container);
// Instantiate Middlewares: Final Exception handler & HSTS headers
$container->extend('app', function (\Spot\Api\ApplicationInterface $application, \Pimple\Container $container) {
    return new \Spot\Api\Middleware\ExceptionCatchingMiddleware(new \Spot\Api\Middleware\HstsMiddleware($application), $container['logger']);
});
return $container['app'];
Ejemplo n.º 6
0
<?php

/** @var \Silex\Application $app */
$app = (require_once __DIR__ . '/app.php');
/** @var \Monolog\Logger $log */
$log = $app['monolog'];
Monolog\ErrorHandler::register($app['monolog']);
$type = $argv[1];
$payload = json_decode(file_get_contents($argv[2]), true);
unlink($argv[2]);
$dir = $app['workspace'] . '/' . sha1(mt_rand());
$log->addInfo("Worker started", ['argv' => $argv, 'dir' => $dir]);
$origin = sprintf('https://%s:%s@github.com/%s', $app['github']['user'], $app['github']['password'], $payload['repository']['full_name']);
$commit = $payload['head_commit']['id'];
$log->addInfo("Git info", ['origin' => $origin, 'commit' => $commit]);
try {
    mkdir($dir, 0777, true);
    chdir($dir);
    `git clone {$origin} . --depth=1`;
    `git checkout {$commit}`;
    $log->addInfo("Done cloning");
    /** @var \Pushkin\Pushkin $pushkin */
    $pushkin = $app['pushkin'];
    $pushkin->setUser($payload['repository']['owner']['name']);
    $pushkin->setRepo($payload['repository']['name']);
    $pushkin->setCommit($commit);
    $buildFile = $dir . '/' . 'pushkin.php';
    if (file_exists($buildFile)) {
        try {
            $pushkin->setStatusPending('Starting build');
            /** @var callable $build */
Ejemplo n.º 7
0
        }
        $runner->register();
    } else {
        if (class_exists('Whoops\\Run')) {
            $run = new Whoops\Run();
            $handler = new Whoops\Handler\PrettyPageHandler();
            $handler->setPageTitle('Parvula Error');
            $handler->addDataTable('Parvula', ['Version' => _VERSION_]);
            $run->pushHandler($handler);
            if (Whoops\Util\Misc::isAjaxRequest()) {
                $run->pushHandler(new Whoops\Handler\JsonResponseHandler());
            }
            $run->register();
            if (class_exists('Monolog\\Logger')) {
                // Be sure that Monolog is still register
                Monolog\ErrorHandler::register($c['loggerHandler']);
            }
            return $run;
        }
    }
};
// To parse serialized files in multiple formats
$app['fileParser'] = function () {
    $parsers = ['json' => new \Parvula\Parsers\Json(), 'yaml' => new \Parvula\Parsers\Yaml(), 'yml' => new \Parvula\Parsers\Yaml(), 'php' => new \Parvula\Parsers\Php()];
    return new Parvula\FileParser($parsers);
};
$app['plugins'] = function (Container $c) {
    $pluginMediator = new Parvula\PluginMediator();
    $pluginMediator->attach(getPluginList($c['config']->get('disabledPlugins')));
    return $pluginMediator;
};
Ejemplo n.º 8
0
};
// setup mail handler
$container['mail'] = $container->factory(function ($c) {
    return (new Jacobemerick\Archangel\Archangel())->setLogger($c['logger']);
});
// setup the logger
$container['setup_logger'] = $container->protect(function ($name) use($container) {
    $logger = new Monolog\Logger($name);
    $logPath = __DIR__ . "/logs/{$name}.log";
    $streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO);
    // todo - make this more useful
    // $streamHandler->setFormatter(
    //     new Monolog\Formatter\LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n")
    // );
    $logger->pushHandler($streamHandler);
    Monolog\ErrorHandler::register($logger);
    $container['logger'] = $logger;
});
// adds profiler
$console = new Particletree\Pqp\Console();
$profiler = new Particletree\Pqp\PhpQuickProfiler($startTime);
$profiler->setConsole($console);
$container['console'] = $console;
$container['profiler'] = $profiler;
$container['console']->logMemory($startMemory, 'PHP - Pre-bootstrap memory', true);
// sets up logger, modifes with profiler handler
$pqpHandler = new Jacobemerick\MonologPqp\PqpHandler($container['console']);
$container['setup_logger']($namespace);
$container['logger']->pushHandler($pqpHandler);
// sets up shutdown function to display profiler
register_shutdown_function(function () use($container) {