本文整理汇总了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);
}
}
示例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.");
}
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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);
}
示例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());
}
}
示例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);
}
示例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);
});
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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();
示例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));
}