pushHandler() public method

Pushes an handler on the stack.
public pushHandler ( Monolog\Handler\HandlerInterface $handler )
$handler Monolog\Handler\HandlerInterface
Esempio n. 1
0
 public function pushLogHandler(HandlerInterface $handler)
 {
     if (!isset($this->logger)) {
         $this->logger = new Logger('byjg-anydataset');
     }
     $this->logger->pushHandler($handler);
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $origin = $input->getOption('origin');
     $force = $input->getOption('force');
     $interactive = $input->isInteractive();
     $this->logger->pushHandler(new ConsoleHandler($output));
     $dispatcher = $this->sourceCleaner->getEventDispatcher();
     // listen to clean event
     $dispatcher->addListener(IoEvents::PRE_CLEAN_SOURCE, function (SourceEvent $event) use($output) {
         $source = $event->getSource();
         $output->writeln(sprintf('<fg=red>- %s:%s</>', $source->getOrigin()->getName(), $source->getOriginalId()));
     });
     if ($force) {
         $voter = new ThresholdVoter(function () {
             return true;
         }, $dispatcher);
     } else {
         $voter = new ThresholdVoter(function ($count, $total, $max, $message) use($output, $interactive) {
             $output->writeln($message);
             // see if we can ask the user to confirm cleanup
             $question = '<question>> Clean these sources anyway? [y]</question> ';
             return $interactive && $this->getDialogHelper()->askConfirmation($output, $question);
         }, $dispatcher);
     }
     $numCleaned = $this->clean($voter, $origin);
     $output->writeln(sprintf('<info>%s</info> sources cleaned', $numCleaned));
     return 0;
 }
 /**
  * @test
  */
 public function itShouldCollect()
 {
     $this->serializer->normalize(Argument::any())->shouldBeCalled()->willReturn([]);
     $this->logger->pushHandler(Argument::any())->shouldBeCalled()->willReturn(true);
     $this->logger->info(Argument::type('string'), Argument::type('array'))->shouldBeCalled();
     $this->collector->collect($this->requestObject, ['logFile' => 'test.log']);
 }
Esempio n. 4
0
 public function beforeTest(TestEvent $e)
 {
     $this->logger = new \Monolog\Logger(Descriptor::getTestFileName($e->getTest()));
     $this->logger->pushHandler($this->logHandler);
     $this->logger->info('------------------------------------');
     $this->logger->info("STARTED: " . ucfirst(Descriptor::getTestAsString($e->getTest())));
 }
 /**
  * @see Console\Command\Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $start = microtime(true);
     $this->output = $output;
     $this->output->write('Extracting datas... ');
     $logger = new Logger('Builder');
     $logger->pushHandler(new NullHandler());
     if ($input->getOption('verbose')) {
         $logger->pushHandler(new StreamHandler('php://stdout'));
     }
     $dumper = new InformationDumper(new Exiftool($logger));
     $dump = $dumper->listDatas(InformationDumper::LISTTYPE_SUPPORTED_XML);
     $this->output->writeln('Done !');
     $this->output->writeln('Generating classes... ');
     $this->extractDump($dump);
     if (!$input->getOption('write')) {
         $this->output->writeln('These classes were not written. Use --write to write on disk');
     } else {
         $this->output->writeln('Erasing previous files... ');
         system('rm -R ' . __DIR__ . '/../../Driver/Tag/*');
         system('rm -R ' . __DIR__ . '/../../Driver/Type/*');
         $this->output->writeln('Writing files... ');
         $this->writeClasses($input->getOption('force'));
     }
     $this->output->writeln(sprintf('%d classes generated in %d seconds (%d Mb)', count($this->classes), microtime(true) - $start, memory_get_peak_usage() >> 20));
 }
 /**
  * Registers services on the given app.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app['hipchat'] = $app->share(function () use($app) {
         if (empty($app['hipchat.rooms'])) {
             return new NullLogger();
         }
         $log = new TargetMappingLogger();
         $app['hipchat.configure']($log);
         return $log;
     });
     $app['hipchat.configure'] = $app->protect(function (TargetMappingLogger $log) use($app) {
         $roomConfigs = $app['hipchat.rooms'];
         $defaults = ['targets' => [], 'name' => 'HipChat', 'notify' => false, 'level' => Logger::INFO, 'bubble' => true, 'useSSL' => true, 'format' => 'text', 'host' => 'api.hipchat.com', 'version' => HipChatHandler::API_V2, 'guzzle' => false];
         if (isset($roomConfigs['_default'])) {
             $defaults = $roomConfigs['_default'] + $defaults;
             unset($roomConfigs['_default']);
         }
         foreach ($roomConfigs as $roomConfig) {
             $roomConfig += $defaults;
             $logger = new Logger('hcm');
             if (!isset($roomConfig['room']) || !isset($roomConfig['token'])) {
                 throw new InvalidArgumentException('missing room/token configuration');
             }
             if (isset($roomConfig['guzzle']) && is_array($roomConfig['guzzle'])) {
                 $logger->pushHandler(new GuzzleHipChatHandler(new Client('', $this->prepareGuzzleOptions($roomConfig['guzzle'])), $roomConfig['token'], $roomConfig['room'], $roomConfig['name'], $roomConfig['notify'], $roomConfig['level'], $roomConfig['bubble'], $roomConfig['useSSL'], $roomConfig['format'], $roomConfig['host'], $roomConfig['version']));
             } else {
                 $logger->pushHandler(new HipChatHandler($roomConfig['token'], $roomConfig['room'], $roomConfig['name'], $roomConfig['notify'], $roomConfig['level'], $roomConfig['bubble'], $roomConfig['useSSL'], $roomConfig['format'], $roomConfig['host'], $roomConfig['version']));
             }
             $log->addLogger($logger, $roomConfig['targets']);
         }
     });
 }
Esempio n. 7
0
 /**
  * @param Config $config
  */
 public function __construct(Config $config)
 {
     $this->config = $config;
     // Set up logging
     $this->log = new Logger('GeoPalMap');
     $this->log->pushHandler(new StreamHandler($this->config->getLogFilePath(), Logger::WARNING));
 }
Esempio n. 8
0
 public function register(Container $container)
 {
     $logger = new Logger('app');
     $logger->pushHandler(new StreamHandler(__DIR__ . '/../../data/debug.log', Logger::DEBUG));
     $logger->pushHandler(new SyslogHandler('kanboard', LOG_USER, Logger::DEBUG));
     $container['logger'] = $logger;
 }
Esempio n. 9
0
 public static function ins($space = 'default')
 {
     //获取配置
     $config = \Yaf\Application::app()->getConfig();
     //项目名
     $projName = isset($config->projName) ? strtolower($config->projName) : 'default';
     $channel = $projName . '/' . $space;
     $channelAll = $projName . '/_all';
     if (isset(self::$ins[$channel])) {
         return self::$ins[$channel];
     }
     //日志配置
     if (!isset($config->log)) {
         throw new Exception('must config the logger first.');
     }
     $logger = new MonoLogger($space);
     $syslog = new SyslogHandler($channel, LOG_LOCAL6, self::$logLevels[$config->log->level]);
     $syslogAll = new SyslogHandler($channelAll, LOG_LOCAL6, self::$logLevels[$config->log->level]);
     //设置日志格式
     $formatter = new LineFormatter("%channel% %level_name%: %message% %context% %extra%");
     $syslog->setFormatter($formatter);
     $syslogAll->setFormatter($formatter);
     $logger->pushHandler($syslog);
     $logger->pushHandler($syslogAll);
     //增加pid
     $processor = new ProcessIdProcessor();
     $logger->pushProcessor($processor);
     //与psr3 context保持一致
     $processor = new PsrLogMessageProcessor();
     $logger->pushProcessor($processor);
     self::$ins[$channel] = $logger;
     return self::$ins[$channel];
 }
Esempio n. 10
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = new Configuration(file_get_contents(__DIR__ . '/../../../config/config.json'));
     $resolver = new SpawnResolver($configuration, CpuInfo::detect());
     $factory = new Factory();
     $classname = $resolver->getClassName();
     if ($input->getOption('verbose')) {
         $outputLogger = new StreamHandler('php://stdout');
     } else {
         $outputLogger = new NullHandler();
     }
     $workers = new \ArrayIterator();
     for ($i = 1; $i <= $resolver->getSpawnQuantity(); $i++) {
         $output->write("Launching Worker <info>{$i}</info> ...");
         $logger = new Logger('Worker-' . $i);
         $logger->pushHandler($outputLogger);
         $logger->pushHandler(new RotatingFileHandler(__DIR__ . '/../../../logs/worker-' . $i . '.logs', 3));
         $worker = new Worker('Worker-' . $i, new \GearmanWorker(), $logger);
         foreach ($configuration['gearman-servers'] as $server) {
             $worker->addServer($server['host'], $server['port']);
         }
         $worker->setFunction(new $classname($configuration, $logger, $factory));
         $workers->append($worker);
         $output->writeln("Success !");
     }
     $manager = new ProcessManager(new EventDispatcher());
     $manager->process($workers, function (Worker $worker) {
         $worker->run();
     });
 }
Esempio n. 11
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     self::$logger = new Logger('filefindtest');
     self::$logger->pushHandler(new TestHandler());
     self::$logger->pushHandler(new StreamHandler('test.log'));
 }
Esempio n. 12
0
 public function setUp()
 {
     parent::setUp();
     $this->monolog = new Monolog\Logger('log-decorator');
     $this->handler = new Monolog\Handler\TestHandler();
     $this->monolog->pushHandler($this->handler);
 }
Esempio n. 13
0
 public function work()
 {
     $identity = $this->identify();
     $this->logger->notice(sprintf('%s waiting for work on queue(s) [%s]', $identity, join(', ', $this->queues)));
     for (;;) {
         $job = $this->metro->pop($this->queues, $this);
         if (null !== $job) {
             $jobHandler = $this->metro->createTaskLogHander($job->getId());
             $this->logger->pushHandler($jobHandler);
             $this->logger->pushProcessor(function ($record) use($job) {
                 $record['extra']['job_id'] = $job->getId();
                 return $record;
             });
             $this->workOn($job, $jobHandler);
             $this->logger->popHandler();
             $this->logger->popProcessor();
         }
         if ($this->interval <= 0) {
             return;
         }
         if (null === $job) {
             if ($this->drainMode) {
                 $this->logger->notice(sprintf('%s exiting because all queues are empty', $identity));
                 return;
             }
             usleep($this->interval * 1000.0);
         }
     }
 }
Esempio n. 14
0
 /**
  * @param resource $stream
  * @param integer  $level  The minimum logging level at which this handler will be triggered
  * @param Boolean  $bubble Whether the messages that are handled can bubble up the stack or not
  */
 public function addDBHandler($stream = null, $level = \Monolog\Logger::DEBUG, $bubble = true)
 {
     if (empty($stream)) {
         $stream = new DBHandler($this->logger->getName() . '_log', $level, $bubble);
     }
     $this->logger->pushHandler($stream);
 }
Esempio n. 15
0
 /**
  * @param string $versionType
  */
 public function __construct($versionType = 'master')
 {
     $this->errorStackTraces = [];
     $this->logger = new Logger('Exceptions');
     $this->logger->pushHandler(new StreamHandler(__DIR__ . '/../data/logs/exceptions.log', Logger::DEBUG));
     $this->versionType = $versionType;
 }
Esempio n. 16
0
 public function __construct()
 {
     $this->pizzaLog = new Logger('pizzas');
     $this->pizzaLog->pushHandler(new StreamHandler('logs/pizza.log', Logger::INFO));
     $this->log = new Logger('simpleReceive');
     $this->log->pushHandler(new StreamHandler('logs/simpleReceive.log', Logger::INFO));
 }
Esempio n. 17
0
 /**
  * Initialize the log manager using custom handler
  *
  * @param string $name The loggin channel
  * @param  HandlerInterface $handler Handler to be user to save the log
  * @return void
  */
 public static function listen($name, HandlerInterface $handler)
 {
     if (null === self::$logger) {
         self::$logger = new Logger($name);
     }
     self::$logger->pushHandler($handler);
 }
Esempio n. 18
0
 public function __construct($logFile)
 {
     $this->_logFile = $logFile;
     // Force autoloading
     Mage::dispatchEvent('add_spl_autoloader');
     // Initialize level mapping only after the Logger class is loaded
     $this->__initLevelMapping();
     $this->_logger = new Logger('monolog');
     $handlers = Mage::getStoreConfig('magemonolog/handlers');
     if (!is_null($handlers) && is_array($handlers)) {
         foreach ($handlers as $handlerModel => $handlerValues) {
             $isActive = Mage::getStoreConfigFlag('magemonolog/handlers/' . $handlerModel . '/active');
             if (!$isActive) {
                 continue;
             }
             $args = array();
             if (array_key_exists('params', $handlerValues)) {
                 $args = $handlerValues['params'];
             }
             $handlerWrapper = Mage::getModel('aleron75_magemonolog/handlerWrapper_' . $handlerModel, $args);
             if (array_key_exists('formatter', $handlerValues) && array_key_exists('class', $handlerValues['formatter'])) {
                 $class = new ReflectionClass('\\Monolog\\Formatter\\' . $handlerValues['formatter']['class']);
                 $formatter = $class->newInstanceArgs($handlerValues['formatter']['args']);
                 $handlerWrapper->setFormatter($formatter);
             }
             $this->_logger->pushHandler($handlerWrapper->getHandler());
         }
     }
 }
Esempio n. 19
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $handlers = [NullHandler::class];
     if (isset($config['log']['handlers'])) {
         $handlers = $config['log']['handlers'];
     }
     if (!is_array($handlers)) {
         throw new \RuntimeException('Log handlers config must be an array of class names, factories, or instances.');
     }
     $logger = new Logger('stokq');
     foreach ($handlers as $handler) {
         if (is_string($handler) && class_exists($handler)) {
             $logger->pushHandler(new $handler());
         } else {
             if (is_callable($handler)) {
                 $logger->pushHandler($handler($serviceLocator));
             } else {
                 if ($handler instanceof AbstractHandler) {
                     $logger->pushHandler($handler);
                 } else {
                     throw new \RuntimeException('Invalid logger, `log.handlers` config must be an instance of AbstractHandler, class name, of factory');
                 }
             }
         }
     }
     return $logger;
 }
 /**
  * Create the logger
  *
  * @param bool $verbose
  *
  * @return \Monolog\Logger
  */
 public static function create($verbose = false, $debug = false)
 {
     $enabled = defined('EXTENDER_LOG_ENABLED') ? filter_var(EXTENDER_LOG_ENABLED, FILTER_VALIDATE_BOOLEAN) : false;
     $name = defined('EXTENDER_LOG_NAME') ? EXTENDER_LOG_NAME : 'extender';
     $level = self::getLevel(defined('EXTENDER_LOG_LEVEL') ? EXTENDER_LOG_LEVEL : 'ERROR');
     $target = defined('EXTENDER_LOG_TARGET') ? EXTENDER_LOG_TARGET : null;
     $logger = new Logger($name);
     if ($enabled) {
         if (is_null($target)) {
             $logger->pushHandler(new ErrorLogHandler());
         } else {
             $logger->pushHandler(new StreamHandler(defined('EXTENDER_LOG_FOLDER') ? EXTENDER_LOG_FOLDER . $target : $target, $level));
         }
     }
     if ($debug) {
         $logger->pushHandler(new ConsoleHandler(self::getLevel("DEBUG")));
     } else {
         if ($verbose) {
             $logger->pushHandler(new ConsoleHandler(self::getLevel("NOTICE")));
         } else {
             $logger->pushHandler(new NullHandler($level));
         }
     }
     return $logger;
 }
Esempio n. 21
0
 public function beforeTest(TestEvent $e)
 {
     $this->logger = new \Monolog\Logger($e->getTest()->getFileName());
     $this->logger->pushHandler($this->logHandler);
     $this->logger->info('------------------------------------');
     $this->logger->info("STARTED: " . ucfirst($e->getTest()->getName(false)));
 }
Esempio n. 22
0
 public function pushLogHandler(HandlerInterface $handler)
 {
     if (!isset($this->logger)) {
         $this->logger = new Logger('byjg-cache-engine');
     }
     $this->logger->pushHandler($handler);
 }
Esempio n. 23
0
 /**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->logger = new Logger('thinframe.events');
     $this->logger->pushHandler(new NullHandler());
     $this->dispatcher = new Dispatcher();
     $this->dispatcher->setLogger($this->logger);
 }
Esempio n. 24
0
 public static function getLogger()
 {
     if (is_null(self::$logger)) {
         self::$logger = new Logger('sdk_logger');
         self::$logger->pushHandler(self::getLoggerHandler());
     }
     return self::$logger;
 }
Esempio n. 25
0
 public static function writeLog($level, $message, $context, $model)
 {
     $logger = new Logger($model);
     $env = \Container::getInstance()->getEnvironment();
     $logger->pushHandler(new StreamHandler(static::$cache_dir . '/' . $env . '.log', self::$levels[$level]));
     $logger->pushHandler(new FirePHPHandler());
     return $logger->{$level}($message, $context);
 }
Esempio n. 26
0
 protected function initLogger()
 {
     $this->log = new Logger(uniqid());
     $dir = $this->config['logging']['dir'] . "/";
     $this->log->pushHandler(new StreamHandler($dir . date("Y-m-d") . ".log", $this->config['logging']['verbosityLog']));
     $this->log->pushHandler(new StreamHandler($dir . date("Y-m-d") . ".log", $this->config['logging']['verbosityError']));
     $this->log->pushHandler(new BrowserConsoleHandler());
 }
Esempio n. 27
0
 /**
  * Install constructor.
  * @param Install $install
  * @param Response $response
  */
 public function __construct(Install $install, Response $response)
 {
     $this->install = $install;
     // create a log channel
     $this->logger = new Logger('name');
     $this->logger->pushHandler(new StreamHandler(ROOT . DS . 'error.log', Logger::WARNING));
     $this->response = $response;
 }
Esempio n. 28
0
 public function setUp()
 {
     Simple::clearLogger();
     $this->logger = new Logger("justALogger");
     $this->handler = new TestHandler();
     $this->logger->pushHandler($this->handler);
     Simple::setLogger($this->logger);
 }
Esempio n. 29
0
 public function registerLogging()
 {
     $formatter = new LineFormatter(null, null, true, true);
     $stream = new StreamHandler(logdir() . 'error.log', Logger::ERROR);
     $stream->setFormatter($formatter);
     $this->log = new Logger('default');
     $this->log->pushHandler($stream);
 }
Esempio n. 30
0
 /**
  * Get the logger instance.
  *
  * @return \Monolog\Logger
  */
 public static function getLoggerInstance()
 {
     if (static::$log === null) {
         static::$log = new Logger('elasticsearch-indexer');
         static::$log->pushHandler(new StreamHandler(static::getFilePath(), Logger::ERROR));
     }
     return static::$log;
 }