本文整理匯總了PHP中Psr\Log\LoggerInterface::pushHandler方法的典型用法代碼示例。如果您正苦於以下問題:PHP LoggerInterface::pushHandler方法的具體用法?PHP LoggerInterface::pushHandler怎麽用?PHP LoggerInterface::pushHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Psr\Log\LoggerInterface
的用法示例。
在下文中一共展示了LoggerInterface::pushHandler方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
if (!is_file($file)) {
throw new RuntimeException('File does not exists');
}
$verbose = $output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
if (!$verbose) {
$this->logger->pushHandler(new NullHandler());
}
try {
$this->connection->beginTransaction();
$result = $this->importService->import(file_get_contents($file));
$this->connection->commit();
$output->writeln('Import successful!');
$output->writeln('The following actions were done:');
$output->writeln('');
foreach ($result as $message) {
$output->writeln('- ' . $message);
}
} catch (\Exception $e) {
$this->connection->rollback();
$output->writeln('An exception occured during import. No changes are applied to the database.');
$output->writeln('');
$output->writeln('Message: ' . $e->getMessage());
$output->writeln('Trace: ' . $e->getTraceAsString());
}
if (!$verbose) {
$this->logger->popHandler();
}
}
示例2: setUp
/**
* Set up test environment
*/
public function setUp()
{
parent::setUp();
$this->link = new \MySQLi('localhost', 'root', '');
if ($this->link->connect_error) {
throw new \RuntimeException('Failed to connect to database. MySQL said: ' . $this->link->connect_error);
}
if (!$this->link->select_db('activecollab_jobs_queue_commands_test')) {
throw new \RuntimeException('Failed to select database.');
}
$this->connection = new MysqliConnection($this->link);
$this->queue = new MySqlQueue($this->connection);
$this->dispatcher = new Dispatcher($this->queue);
$this->log_file_path = dirname(__DIR__) . '/logs/' . date('Y-m-d') . '.txt';
if (is_file($this->log_file_path)) {
unlink($this->log_file_path);
}
$this->log = new Logger('cli');
$handler = new StreamHandler($this->log_file_path, Logger::DEBUG);
$formatter = new LineFormatter();
$formatter->includeStacktraces(true);
$handler->setFormatter($formatter);
$this->log->pushHandler($handler);
$this->container = new Container(['dispatcher' => $this->dispatcher, 'log' => $this->log]);
}
示例3: collect
/**
* {@inheritdoc}
*/
public function collect(RequestObject $requestObject, array $parameters = [])
{
$parameters = $this->resolveCollectorParameters($parameters);
$logFile = sprintf('%s/%s.%s', $this->logFolder, $this->kernelEnvironment, $parameters['logFile']);
$this->logger->pushHandler(new StreamHandler($logFile));
$this->logger->info('request_collector.collect', $this->serializer->normalize($requestObject));
}
示例4: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->log = $log = new Logger('Insight test');
$this->log->pushHandler(new NullHandler());
$this->current_timestamp = new DateTimeValue();
DateTimeValue::setTestNow($this->current_timestamp);
}
示例5: setUp
/**
* @inheritdoc
*/
public function setUp()
{
$this->handler = new ArrayHandler();
$this->handler->setFormatter(new LineFormatter('%level_name% %message%'));
$this->logger = new Logger('test');
$this->logger->pushHandler($this->handler);
$this->logger->pushProcessor(new ContextReplacementProcessor());
}
示例6: __construct
public function __construct($logger = null, $formatter = null)
{
if ($logger instanceof LoggerInterface) {
$this->logger = $logger;
} else {
$this->logger = new Logger('EvaOAuth');
$this->logger->pushHandler(new StreamHandler($logger, Logger::DEBUG));
}
$this->formatter = $formatter instanceof Formatter ? $formatter : new Formatter($formatter);
}
示例7: __construct
/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger = null)
{
if (is_null($logger)) {
$this->logger = new Logger("monitor");
$this->logger->pushHandler(new NullHandler());
} else {
$this->logger = $logger;
}
$this->pool = new Pool();
}
示例8: __construct
/**
* @param LoggerInterface|null $logger
* @param Mission[]|null $missions
*/
public function __construct(LoggerInterface $logger = null, $missions = null)
{
set_time_limit(0);
if (is_null($logger)) {
$this->logger = new Logger(self::NAME);
$this->logger->pushHandler(new NullHandler());
} else {
$this->logger = $logger;
}
$this->batchAddMissions($missions);
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$parameters = ['host' => $input->getArgument('host'), 'user' => $input->getArgument('username'), 'password' => $input->getArgument('password'), 'dbname' => $input->getArgument('database'), 'driver' => $input->getArgument('driver'), 'charset' => 'utf8'];
$this->connection = $this->getContainer()->get('doctrine.dbal.connection_factory')->createConnection($parameters);
$this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
$path = $this->getContainer()->getParameter('kernel.root_dir') . '/logs/import.log';
$this->logger = $this->getContainer()->get('logger');
$this->logger->pushHandler(new StreamHandler($path, Logger::INFO));
if ($input->getOption('disable-logging')) {
$this->disableLoggableExtension();
}
}
示例10: __construct
public function __construct($config = [])
{
$this->parentConstruct($config);
if (isset($this->logger)) {
return;
}
$this->logger = new Logger('Rock');
if (!$this->handlers) {
$this->handlers = $this->defaultHandlers();
}
foreach ($this->handlers as $level => $ahndler) {
$this->logger->pushHandler($ahndler);
}
}
示例11: getLogger
public static function getLogger()
{
if (!self::$logger) {
self::$logger = new Logger(KBGDC_APP_NAME);
if (getenv('KBGDC_PAPERTRAIL_PORT')) {
$handler = new SyslogUdpHandler("logs.papertrailapp.com", getenv('KBGDC_PAPERTRAIL_PORT'));
} else {
$handler = new SyslogHandler(KBGDC_APP_NAME);
}
$handler->setFormatter(new JsonFormatter());
self::$logger->pushHandler($handler);
}
return self::$logger;
}
示例12: create
/**
* @param string $name
* @param bool $saveOnRedis
*
* @return LoggerInterface
*/
public static function create($name = 'EloGankAPI', $saveOnRedis = false)
{
if (!isset(self::$logger)) {
$verbosity = constant('Monolog\\Logger::' . strtoupper(ConfigurationLoader::get('log.verbosity')));
self::$logger = new Logger($name, array(new ConsoleHandler(new ConsoleOutput(), true, array(OutputInterface::VERBOSITY_NORMAL => $verbosity, OutputInterface::VERBOSITY_VERBOSE => Logger::DEBUG, OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::DEBUG, OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG)), new RotatingFileHandler(ConfigurationLoader::get('log.path'), ConfigurationLoader::get('log.max_file'), $verbosity)));
// Allow the server to retrieve clients logs
if (true === ConfigurationLoader::get('client.async.enabled')) {
self::$redisClient = new Client(sprintf('tcp://%s:%s', ConfigurationLoader::get('client.async.redis.host'), ConfigurationLoader::get('client.async.redis.port')));
if ($saveOnRedis) {
self::$logger->pushHandler(new RedisHandler(self::$redisClient, ConfigurationLoader::get('client.async.redis.key') . '.client.logs', $verbosity));
}
}
}
return self::$logger;
}
示例13: __construct
/**
* @param $app
*/
public function __construct(RenaApp $app)
{
$this->app = $app;
$this->logger = new Logger('projectRena');
$logFile = $this->app->baseConfig->getConfig('logFile', 'Logging', __DIR__ . '/../../logs/app.log');
// Make sure the logfile exists and is writeable
if (!is_writable($logFile)) {
chmod($logFile, 0777);
}
if (!file_exists($logFile)) {
file_put_contents($logFile, "");
}
// Setup the push handler
$this->logger->pushHandler(new StreamHandler($logFile, $this->app->baseConfig->getConfig("logLevel", "Logging", 100), true, 0777));
}
示例14: debugFilePath
/**
* Set different debug file location.
*
* @access public
* @param string $path File path
* @return \carteiro\Mail
*/
public function debugFilePath($path)
{
$this->debug(true);
$this->logger->popHandler();
$this->logger->pushHandler(new StreamHandler($path, Logger::DEBUG));
return $this;
}
示例15: getLogger
/**
* @codeCoverageIgnore
* @return LoggerInterface
*/
public function getLogger()
{
if (!$this->logger instanceof LoggerInterface) {
$this->logger = new Logger(__CLASS__);
$this->logger->pushHandler(new NullHandler());
}
return $this->logger;
}