當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Logger::addCritical方法代碼示例

本文整理匯總了PHP中Monolog\Logger::addCritical方法的典型用法代碼示例。如果您正苦於以下問題:PHP Logger::addCritical方法的具體用法?PHP Logger::addCritical怎麽用?PHP Logger::addCritical使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Monolog\Logger的用法示例。


在下文中一共展示了Logger::addCritical方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: log

 public function log($message, $priority = self::INFO)
 {
     if ($message instanceof \Exception) {
         $message = $message->getMessage();
         $context = [];
     } elseif (is_string($message)) {
         $context = [];
     } else {
         $context = $message;
         unset($context[0]);
         unset($context[1]);
         if (isset($message[1])) {
             $message = preg_replace('#\\s*\\r?\\n\\s*#', ' ', trim($message[1]));
         }
     }
     switch ($priority) {
         case self::DEBUG:
             return $this->monolog->addDebug($message, $context);
         case self::CRITICAL:
             return $this->monolog->addCritical($message, $context);
         case self::ERROR:
             return $this->monolog->addError($message, $context);
         case self::EXCEPTION:
             return $this->monolog->addEmergency($message, $context);
         case self::WARNING:
             return $this->monolog->addWarning($message, $context);
         case 'access':
             return $this->monolog->addNotice($message, $context);
         case 'emergency':
             return $this->monolog->addEmergency($message, $context);
         default:
             return $this->monolog->addInfo($message, $context);
     }
 }
開發者ID:bazo,項目名稱:nette-monolog-extension,代碼行數:34,代碼來源:MonologAdapter.php

示例2: __construct

 /**
  * @param array $config
  * @throws \Exception
  */
 protected function __construct($config)
 {
     parent::__construct($config);
     $this->memcache = new \Memcache();
     /**
      * This is something tricky in PHP. If you use pconnect (p=persistent) the connection will remain open all the time.
      * This is not a bad thing since we're using the cache all the time (you don't turn off the light of the kitchen if you're running in and out, switching it too much would even consume more)
      * In memcache, the old but stable implementation in PHP of memcached the persistent connection works like charm
      * In memcached however there is a severe bug which leads to a memory leak. If you'd take over code from this class to implement memcached, DON'T use the persistent connect!
      */
     if (!isset($this->config["host"])) {
         // the default host for memcached localhost
         $this->config["host"] = "localhost";
     }
     if (!isset($this->config["port"])) {
         // the default port for memcached is 11211
         $this->config["port"] = 11211;
     }
     if (!$this->memcache->pconnect($this->config["host"], $this->config["port"])) {
         if (isset($this->config["log_dir"])) {
             $log_dir = rtrim($this->config["log_dir"], "/");
             $log = new Logger('cache');
             $log->pushHandler(new StreamHandler($log_dir . "/log_" . date('Y-m-d') . ".txt", Logger::CRITICAL));
             $log->addCritical("Could not connect to memcached.", $this->config);
         } else {
             /*
              * if we have no log directory, it's no use to throw a TDTException
              */
             throw new \Exception("No connection could be made to the memcache. Please check your given configuration.");
         }
     }
 }
開發者ID:Tjoosten,項目名稱:cache,代碼行數:36,代碼來源:MemCache.php

示例3: log

 /**
  * Log a message
  *
  * @param string $message
  * @param int    $level
  * @param array $context
  * @return void
  */
 public function log($message, $level = Logger::INFO, array $context = [])
 {
     if (!$this->logger) {
         return;
     }
     if (null === $level) {
         $level = Logger::INFO;
     }
     switch ($level) {
         case Logger::DEBUG:
             $this->logger->addDebug($message, $context);
             break;
         case Logger::INFO:
             $this->logger->addInfo($message, $context);
             break;
         case Logger::NOTICE:
             $this->logger->addNotice($message, $context);
             break;
         case Logger::WARNING:
             $this->logger->addWarning($message, $context);
             break;
         case Logger::ERROR:
             $this->logger->addError($message, $context);
             break;
         case Logger::CRITICAL:
             $this->logger->addCritical($message, $context);
             break;
         case Logger::EMERGENCY:
             $this->logger->addEmergency($message, $context);
             break;
         default:
             break;
     }
 }
開發者ID:dwsla,項目名稱:service-mpx,代碼行數:42,代碼來源:AbstractService.php

示例4: log

 /**
  * Отправляет сообщение в лог
  *
  * @param string $message сообщение
  * @param int    $level   уровень
  *
  * @return void
  */
 public function log($message, $level = AbstractLogger::NOTICE)
 {
     if ($level < $this->severity) {
         return;
     }
     switch ($level) {
         case AbstractLogger::EMERGENCY:
             $this->impl->addEmergency($message);
             break;
         case AbstractLogger::ALERT:
             $this->impl->addAlert($message);
             break;
         case AbstractLogger::CRITICAL:
             $this->impl->addCritical($message);
             break;
         case AbstractLogger::ERROR:
             $this->impl->addError($message);
             break;
         case AbstractLogger::WARNING:
             $this->impl->addWarning($message);
             break;
         case AbstractLogger::NOTICE:
             $this->impl->addNotice($message);
             break;
         case AbstractLogger::INFO:
             $this->impl->addInfo($message);
             break;
         case AbstractLogger::DEBUG:
             $this->impl->addDebug($message);
             break;
     }
 }
開發者ID:itmh,項目名稱:service-tools-old,代碼行數:40,代碼來源:MonologLogger.php

示例5: execute

 /**
  * @param String $query
  * @param array $parameters
  * @return int|null|string
  */
 public function execute(string $query, $parameters = array())
 {
     try {
         $this->pdo->beginTransaction();
         $stmt = $this->pdo->prepare($query);
         $stmt->execute($parameters);
         if ($stmt->errorCode() != 0) {
             $this->pdo->rollBack();
             return 0;
         }
         $returnID = $this->pdo->lastInsertId();
         $this->pdo->commit();
         $stmt->closeCursor();
         return $returnID;
     } catch (\Exception $e) {
         $this->log->addError("There was an error during a query: ", [$e->getMessage()]);
         try {
             $this->pdo = $this->connect();
         } catch (\Exception $e2) {
             $this->log->addCritical("Couldn't reconnect to the database: " . $e->getMessage());
             die(1);
         }
     }
     return null;
 }
開發者ID:sovereignbot,項目名稱:citadel,代碼行數:30,代碼來源:Db.php

示例6: __construct

 public function __construct($errorcode, array $parameters = array(), array $config = array())
 {
     $this->config = $config;
     $this->errorcode = $errorcode;
     $this->parameters = $parameters;
     $exceptions = parse_ini_file("exceptions.ini", true);
     if (isset($exceptions[$errorcode])) {
         $this->exceptionini = $exceptions[$errorcode];
         //create the message of the exception by filling out the parameters, if the message exists of course
         $i = 1;
         if (isset($this->exceptionini["message"])) {
             foreach ($this->parameters as $param) {
                 $to_replace = "\$" . $i;
                 if (!is_string($param)) {
                     $param = print_r($param, true);
                 }
                 $this->exceptionini["message"] = str_replace($to_replace, $param, $this->exceptionini["message"]);
                 $i++;
             }
         }
     } else {
         if (isset($config["log_dir"])) {
             $log = new Logger('error_handler');
             $log_dir = rtrim($this->config["log_dir"], "/");
             $log->pushHandler(new StreamHandler($log_dir . "/log_" . date('Y-m-d') . ".txt", Logger::CRITICAL));
             $log->addCritical("Could not find an exception with errorcode " . $this->errorcode . ".");
         }
         if (isset($config["url"])) {
             $url = rtrim($config["url"], "/");
             header("Location: " . $url . "/critical");
         }
     }
     parent::__construct($this->getMsg(), $errorcode);
 }
開發者ID:tdt,項目名稱:exceptions,代碼行數:34,代碼來源:TDTException.php

示例7: run

 public function run(Repository $repository, GitSource $source)
 {
     $this->logger = new Logger($repository->getRepository(), array($this->handler));
     try {
         $docsRepository = null;
         $this->initSourcePath($repository, $source);
         $this->checkoutSource($repository, $source);
         $this->buildDefaultSettings($repository, $source);
         $this->buildSettings($repository, $docsRepository, $source);
         $this->checkBranch($repository, $docsRepository, $source);
         $this->initDocsPath($repository, $docsRepository, $source);
         $this->prepareDocs($repository, $docsRepository, $source);
         $this->generateDocs($repository, $docsRepository, $source);
         $this->pushDocs($repository, $docsRepository, $source);
         $this->updateHistory($repository, $docsRepository, $source);
     } catch (\Exception $exception) {
         $this->logger->addCritical($exception->getMessage() . "\n" . $exception->getTraceAsString());
     }
 }
開發者ID:kdambekalns,項目名稱:apigenerator.org,代碼行數:19,代碼來源:AbstractGenerator.php

示例8: it_should_sent_message

 /**
  * @test
  */
 public function it_should_sent_message()
 {
     $spy = new MessageSenderSpy();
     $config = SmsapiConfigMother::createDefault();
     $handler = new SmsapiHandler($spy, new SmsapiFormatterFactory($config), $config);
     $logger = new Logger('example');
     $logger->pushHandler($handler);
     $logger->addCritical('some critical bug');
     $this->assertTrue($spy->isSent);
 }
開發者ID:smsapi,項目名稱:monolog-smsapi,代碼行數:13,代碼來源:SmsapiHandlerTest.php

示例9: handle

 /**
  * Handle the event.
  *
  * @param UpdateAvailable $event
  */
 public function handle(UpdateAvailable $event)
 {
     if (config('self-update.log_events')) {
         $this->logger->addInfo('[' . $event->getEventName() . '] event: Notification triggered.');
     }
     $sendToAddress = config('self-update.mail_to.address');
     $sendToName = config('self-update.mail_to.name');
     $subject = config('self-update.mail_to.subject_update_available');
     if (empty($sendToAddress)) {
         $this->logger->addCritical('[' . $event->getEventName() . '] event: ' . 'Missing recipient email address. Please set SELF_UPDATER_MAILTO_ADDRESS in your .env file.');
     }
     if (empty($sendToName)) {
         $this->logger->addWarning('[' . $event->getEventName() . '] event: ' . 'Missing recipient email name. Please set SELF_UPDATER_MAILTO_NAME in your .env file.');
     }
     $this->mailer->send('vendor.self-update.mails.update-available', ['newVersion' => $event->getVersionAvailable()], function ($m) use($subject, $sendToAddress, $sendToName) {
         $m->subject($subject);
         $m->from(config('mail.from.address'), config('mail.from.name'));
         $m->to($sendToAddress, $sendToName);
     });
 }
開發者ID:codedge,項目名稱:laravel-selfupdater,代碼行數:25,代碼來源:SendUpdateAvailableNotification.php

示例10: it_correctly_identifies_the_info

 /**
  * @test
  */
 public function it_correctly_identifies_the_info()
 {
     $bugsnag = new Bugsnag_Client(self::APIKEY);
     $logger = new Logger('my_logger');
     $logger->pushHandler(new BugsnagHandler(Logger::INFO, true, 'BugsnagMonolog', $bugsnag));
     $logger->addInfo('info', ['some' => 'message']);
     $logger->addError('error', ['some' => 'message']);
     $logger->addAlert('alert', ['some' => 'message']);
     $logger->addCritical('critical', ['some' => 'message']);
     $logger->addDebug('debug', ['some' => 'message']);
     $logger->addWarning('warning', ['some' => 'message']);
     $logger->addEmergency('emergency', ['some' => 'message']);
     $logger->addNotice('notice', ['some' => 'message']);
     $this->assertTrue(true);
 }
開發者ID:zae,項目名稱:monolog-bugsnag,代碼行數:18,代碼來源:BugsnagLoggerTest.php

示例11: checkResult

 /**
  * @brief Check the result for unexpected errors. If found, treat them as fatal.
  * @param resource $result command result object
  * @param string $sqlStatement SQL command (optional)
  */
 protected function checkResult($result, $sqlStatement = "")
 {
     if ($result !== false) {
         return;
     }
     $lastError = "";
     if ($this->dbDriver->isConnected()) {
         $lastError = $this->dbDriver->getLastError();
         $this->logger->addCritical($lastError);
         if ($this->transactionDepth > 0) {
             $this->dbDriver->rollback();
         }
     } else {
         $this->logger->addCritical("DB connection lost.");
     }
     $message = "error executing: {$sqlStatement}\n\n{$lastError}";
     throw new Exception($message);
 }
開發者ID:DanielDobre,項目名稱:fossology,代碼行數:23,代碼來源:DbManager.php

示例12: receiveSig

 public function receiveSig($sig)
 {
     $this->signalled = true;
     switch ($sig) {
         case SIGTERM:
             $this->logger->addError("Received SIGTERM");
             exit($this->stop() ? 0 : -1);
             break;
         case SIGINT:
             $this->logger->addWarning("Received SIGINT");
             exit($this->stop() ? 0 : -1);
             break;
         default:
             $this->logger->addCritical("Received Unknown Signal {$sig}");
             exit($this->stop() ? 127 : 127);
             break;
     }
 }
開發者ID:dcousineau,項目名稱:phorever,代碼行數:18,代碼來源:Phorever.php

示例13: getContents

 /**
  * Get the contents of a given URL (via GET)
  * @param  string $pageUrl The URL of the page to get the contents of
  * @return string
  */
 private function getContents(&$pageUrl)
 {
     // Init CURL
     $curl = curl_init();
     @curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 1, CURLOPT_URL => $pageUrl, CURLOPT_TIMEOUT_MS => $this->timeout, CURLOPT_SSL_VERIFYPEER => $this->checkCertificate, CURLOPT_SSL_VERIFYHOST => $this->getVerifyHost(), CURLOPT_USERAGENT => 'mixed-content-scan'));
     // Fetch the response (both head and body)
     $response = curl_exec($curl);
     // Fetch the URL of the page we actually fetched
     $newUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
     if ($newUrl != $pageUrl) {
         // If we started at the rootURL, and it got redirected:
         // --> overwrite the rootUrl so that we use the new one from now on
         if ($pageUrl == $this->rootUrl) {
             // Store the new rootUrl
             $this->setRootUrl($newUrl, false);
             // Update ignore patterns
             $this->setIgnorePatterns($this->ignorePatterns, $pageUrl);
         }
         // Update $pageUrl (pass by reference!)
         $pageUrl = $newUrl;
     }
     // Got an error?
     $curl_errno = curl_errno($curl);
     $curl_error = curl_error($curl);
     if ($curl_errno > 0) {
         $this->logger->addCritical('cURL Error (' . $curl_errno . '): ' . $curl_error);
     }
     // Extract the response head and response body from the response
     $headers = substr($response, 0, curl_getinfo($curl, CURLINFO_HEADER_SIZE));
     $body = substr($response, -curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD));
     // Close it
     @curl_close($curl);
     // If the headers contain `Content-Security-Policy: upgrade-insecure-requests`
     // then the page should be skipped, as the browser will (should) then automatically
     // upgrade all requests.
     // @ref https://w3c.github.io/webappsec-upgrade-insecure-requests/
     // Return the fetched contents
     return $body;
 }
開發者ID:bramus,項目名稱:mixed-content-scan,代碼行數:44,代碼來源:Scanner.php

示例14: array

$view = $app->view();
$view->parserExtensions = array(new \Slim\Views\TwigExtension());
$redis = new Predis\Client(array("scheme" => "tcp", "host" => "127.0.0.1", "port" => 6379));
$app->get('/hello/:name', function ($name) use($app) {
    $logPath = '/tmp/mono.log';
    $logger = new Logger('foo_test');
    $logger->pushHandler(new StreamHandler($logPath, Logger::DEBUG));
    // $logger->info()
    $logger->addInfo('info_bar');
    // $logger->notice()
    $logger->addNotice('notice_bar');
    // $logger->warning(), $logger->warn()
    $logger->addWarning('warning_bar');
    // $logger->error(), $logger->err()
    $logger->addError('error_bar');
    // $logger->critical(), $logger->crit()
    $logger->addCritical('critical_bar');
    // $logger->alert()
    $logger->addAlert('alert_bar');
    // $logger->emergency(), $logger->emerg()
    $logger->addEmergency('emergency_bar');
    $app->render('index.html', array('name' => $name));
});
$app->get('/redis', function () use($redis) {
    // PING
    echo $redis->ping();
    $redis->set('key', 'value');
    $value = $redis->get('key');
    echo "key: " . $value;
});
$app->run();
開發者ID:kura-lab,項目名稱:slim-sample,代碼行數:31,代碼來源:index.php

示例15: RotatingFileHandler

    }
    if (!array_key_exists('exception', $record['context'])) {
        return false;
    }
    return preg_match('/^An error has occured/', $record['message']) === 1;
});
// Create some handlers
$stream = new RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'growl_conf.log');
$stream->setFilenameFormat('{filename}-{date}', 'Ymd');
$logger->pushHandler($stream);
try {
    $resourceDir = __DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
    $notifications = array(GrowlHandler::DEBUG => array('icon' => $resourceDir . 'green.png'), GrowlHandler::INFO => array('icon' => $resourceDir . 'green.png'), GrowlHandler::NOTICE => array('icon' => $resourceDir . 'yellow.png'), GrowlHandler::WARNING => array('icon' => $resourceDir . 'yellow.png'), GrowlHandler::ERROR => array('icon' => $resourceDir . 'red.png'), GrowlHandler::CRITICAL => array('icon' => $resourceDir . 'red.png'), GrowlHandler::ALERT => array('icon' => $resourceDir . 'red.png'), GrowlHandler::EMERGENCY => array('icon' => $resourceDir . 'red.png'));
    $options = array('AppIcon' => dirname(__DIR__) . '/vendor/pear-pear.php.net/Net_Growl/data/Net_Growl/data/128/growl-starkicon.png');
    $growl = new GrowlHandler(array('name' => 'My Custom Growl', 'notifications' => $notifications, 'options' => $options));
    $growl->setFormatter(new LineFormatter("%message%\n%level_name%"));
    $logger->pushHandler(new CallbackFilterHandler($growl, $filters));
} catch (\Exception $e) {
    // Growl server is probably not started
    echo $e->getMessage(), PHP_EOL, PHP_EOL;
}
// You can now use your logger
$logger->addInfo('My logger is now ready');
// This record won't be stopped by the $filters rules, but by the growl $notifications config
$logger->addDebug('A debug message.');
$logger->addError('An error has occured. Will be logged to file BUT NOT notified by Growl.');
try {
    throw new \RuntimeException();
} catch (\Exception $e) {
    $logger->addCritical('An error has occured. Will be logged to file AND notified by Growl.', array('exception' => $e));
}
開發者ID:ElectroLutz,項目名稱:monolog-growlhandler,代碼行數:31,代碼來源:growl_conf.php


注:本文中的Monolog\Logger::addCritical方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。