本文整理汇总了PHP中Monolog\Logger::pushHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::pushHandler方法的具体用法?PHP Logger::pushHandler怎么用?PHP Logger::pushHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monolog\Logger
的用法示例。
在下文中一共展示了Logger::pushHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pushLogHandler
public function pushLogHandler(HandlerInterface $handler)
{
if (!isset($this->logger)) {
$this->logger = new Logger('byjg-anydataset');
}
$this->logger->pushHandler($handler);
}
示例2: execute
/**
* @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;
}
示例3: itShouldCollect
/**
* @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']);
}
示例4: beforeTest
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())));
}
示例5: execute
/**
* @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));
}
示例6: register
/**
* 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']);
}
});
}
示例7: __construct
/**
* @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));
}
示例8: register
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;
}
示例9: ins
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];
}
示例10: execute
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();
});
}
示例11: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$logger = new Logger('filefindtest');
self::$logger->pushHandler(new TestHandler());
self::$logger->pushHandler(new StreamHandler('test.log'));
}
示例12: setUp
public function setUp()
{
parent::setUp();
$this->monolog = new Monolog\Logger('log-decorator');
$this->handler = new Monolog\Handler\TestHandler();
$this->monolog->pushHandler($this->handler);
}
示例13: work
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);
}
}
}
示例14: addDBHandler
/**
* @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);
}
示例15: __construct
/**
* @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;
}