当前位置: 首页>>代码示例>>PHP>>正文


PHP Logger::setTimezone方法代码示例

本文整理汇总了PHP中Monolog\Logger::setTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::setTimezone方法的具体用法?PHP Logger::setTimezone怎么用?PHP Logger::setTimezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Monolog\Logger的用法示例。


在下文中一共展示了Logger::setTimezone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * {@inheritDoc}
  */
 public function register(Container $container)
 {
     // Append custom settings with missing params from default settings
     $container['settings']['logger'] = self::mergeWithDefaultSettings($container['settings']['logger']);
     /**
      * Add dependency (DI).
      *
      * @param Container $c
      *
      * @return Logger
      */
     $container['logger'] = function (Container $c) {
         $settings = $c['settings']['logger'];
         $loggerFormat = "[%datetime%] %level_name% %message% %context% %extra%\n";
         $loggerTimeFormat = "Y-m-d H:i:s";
         $loggerTimeZone = new DateTimeZone('Europe/Berlin');
         $logger = new Logger($settings['name']);
         if ($settings['color']) {
             $logger->pushProcessor(new ConsoleColorProcessor());
         }
         $logger->pushProcessor(new CleanupProcessor($settings['trimPaths']));
         $logger->pushProcessor(new IntrospectionProcessor(Logger::WARNING));
         $logger->pushProcessor(new ProcessIdProcessor());
         $logger->pushProcessor(new PsrLogMessageProcessor());
         $logger->setTimezone($loggerTimeZone);
         $logger->useMicrosecondTimestamps(false);
         // Using microseconds is buggy (2016-08-04)
         $formatter = new LineFormatter($loggerFormat, $loggerTimeFormat);
         $formatter->ignoreEmptyContextAndExtra(true);
         $defaultHandler = new StreamHandler('php://stdout', $settings['level'], $bubble = false);
         $defaultHandler->setFormatter($formatter);
         $logger->pushHandler($defaultHandler);
         $errorHandler = new StreamHandler('php://stderr', Logger::ERROR, $bubble = false);
         $errorHandler->setFormatter($formatter);
         $logger->pushHandler($errorHandler);
         // Register logger as default PHP error, exception and shutdown handler
         // Note: Make sure only this handler handles errors (set $callPrevious to false)
         $errorHandler = ErrorHandler::register($logger, $errorLevelMap = false, $exceptionLevelMap = false);
         $errorHandler->registerErrorHandler($levelMap = [], $callPrevious = false);
         $errorHandler->registerExceptionHandler($levelMap = [], $callPrevious = false);
         return $logger;
     };
 }
开发者ID:ansas,项目名称:php-component,代码行数:46,代码来源:ConsoleLoggerProvider.php

示例2: __construct

 /**
  * Register this plates view provider with a Pimple container
  *
  * @param string $name
  * @param array  $settings
  */
 public function __construct($name = 'slim-app', $settings = [])
 {
     $this->name = $name;
     $this->monolog = new Logger($this->name);
     $this->settings = array_merge($this->settings, $settings);
     if (null !== $this->settings['timezone']) {
         if (is_string($this->settings['timezone'])) {
             $this->settings['timezone'] = new \DateTimeZone($this->settings['timezone']);
         }
         Logger::setTimezone($this->settings['timezone']);
     }
     $this->monolog->setHandlers($this->settings['handlers']);
     $levels = array_keys(Logger::getLevels());
     if (!in_array(strtoupper($this->settings['level']), $levels)) {
         $this->settings['level'] = 'debug';
     }
     if ($path = $this->settings['directory']) {
         if ($path === 'syslog') {
             $this->useSyslog($this->name, $this->settings['level']);
         } elseif (is_dir($path)) {
             $path .= '/' . $this->name;
             $this->useRotatingFiles($path, $this->settings['level']);
         }
     }
 }
开发者ID:creasi,项目名称:slim-monolog,代码行数:31,代码来源:Monolog.php

示例3: testIntegration

 /** @test */
 public function testIntegration()
 {
     $client = ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
     try {
         $client->ping();
     } catch (NoNodesAvailableException $e) {
         $this->markTestSkipped('Skipped due to a missing instance of Elasticsearch');
     }
     try {
         $client->indices()->delete(['index' => ElasticsearchHandler::DEFAULT_INDEX_NAME]);
     } catch (Missing404Exception $e) {
         // Noop
     }
     $logger = new Logger('application', [new ElasticsearchHandler($client)]);
     $timezone = new \DateTimeZone('UTC');
     $datetime = DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $timezone)->setTimezone($timezone)->format(DateTime::ISO8601);
     $logger->setTimezone($timezone);
     $logger->info('This is a test!');
     sleep(1);
     $results = $client->search(['index' => ElasticsearchHandler::DEFAULT_INDEX_NAME, 'type' => ElasticsearchHandler::DEFAULT_TYPE_NAME, 'body' => ['query' => ['match_all' => new \stdClass()]]]);
     $this->assertGreaterThan(0, $results['hits']['total']);
     $expected = ['message' => 'This is a test!', 'context' => [], 'level' => 200, 'level_name' => 'INFO', 'channel' => 'application', 'datetime' => $datetime, 'extra' => []];
     $this->assertEquals($expected, $results['hits']['hits'][0]['_source']);
 }
开发者ID:atrapalo,项目名称:monolog-elasticsearch,代码行数:25,代码来源:ElasticsearchHandlerTest.php

示例4: testSetTimezone

 /**
  * @dataProvider setTimezoneProvider
  * @covers       Monolog\Logger::setTimezone
  */
 public function testSetTimezone($tz)
 {
     Logger::setTimezone($tz);
     $logger = new Logger('foo');
     $handler = new TestHandler();
     $logger->pushHandler($handler);
     $logger->info('test');
     list($record) = $handler->getRecords();
     $this->assertEquals($tz, $record['datetime']->getTimezone());
 }
开发者ID:saj696,项目名称:pipe,代码行数:14,代码来源:LoggerTest.php

示例5: setTimezone

 /**
  * Set the timezone to be used for the timestamp of log records.
  * 
  * This is stored globally for all Logger instances
  *
  * @param \DateTimeZone $tz Timezone object
  * @static 
  */
 public static function setTimezone($tz)
 {
     return \Monolog\Logger::setTimezone($tz);
 }
开发者ID:samcrosoft,项目名称:MicroTranslate,代码行数:12,代码来源:lumen_ide_helper.php

示例6: array

                // Register a handler that will buffer the event stream and
                // pass events to the nested handler after closing the request
                $wmgMonologConfig['handlers'][$bufferedHandler] = array('class' => '\\MediaWiki\\Logger\\Monolog\\BufferHandler', 'args' => array(function () use($handlerName) {
                    return LoggerFactory::getProvider()->getHandler($handlerName);
                }));
            }
            $handlers[$idx] = $bufferedHandler;
        }
    }
    if ($handlers) {
        // T118057: wrap the collection of handlers in a WhatFailureGroupHandler
        // to swallow any exceptions that might leak out otherwise
        $failureGroupHandler = 'failuregroup|' . implode('|', $handlers);
        if (!isset($wmgMonologConfig['handlers'][$failureGroupHandler])) {
            $wmgMonologConfig['handlers'][$failureGroupHandler] = array('class' => '\\Monolog\\Handler\\WhatFailureGroupHandler', 'args' => array(function () use($handlers) {
                $provider = LoggerFactory::getProvider();
                return array_map(array($provider, 'getHandler'), $handlers);
            }));
        }
        $wmgMonologConfig['loggers'][$channel] = array('handlers' => array($failureGroupHandler), 'processors' => array_keys($wmgMonologProcessors), 'calls' => $wmgMonologLoggerCalls);
    } else {
        // No handlers configured, so use the blackhole route
        $wmgMonologConfig['loggers'][$channel] = array('handlers' => array('blackhole'), 'calls' => $wmgMonologLoggerCalls);
    }
}
$wgMWLoggerDefaultSpi = array('class' => '\\MediaWiki\\Logger\\MonologSpi', 'args' => array($wmgMonologConfig));
// Bug: T99581 - force logger timezone to UTC
// Guard condition needed for Jenkins; class from mediawiki/vendor
if (method_exists('\\Monolog\\Logger', 'setTimezone')) {
    \Monolog\Logger::setTimezone(new DateTimeZone('UTC'));
}
开发者ID:nomoa,项目名称:operations-mediawiki-config,代码行数:31,代码来源:logging.php


注:本文中的Monolog\Logger::setTimezone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。