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); } }
/** * 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; } }
/** * Sets the root URL of the website to scan * @param string $rootUrl * @param bool $limitToPath * @throws Exception If the root URL is invalid */ private function setRootUrl($rootUrl, $limitToPath = true) { // If the rootUrl is *, it means that we'll pass in some URLs manually if ($rootUrl == '*') { $this->rootUrl = $rootUrl; return; } // Make sure the rootUrl is parse-able $urlParts = parse_url($rootUrl); if (!$urlParts || !isset($urlParts['scheme']) || !isset($urlParts['host'])) { $this->logger->addEmergency('Invalid rootUrl!'); throw new Exception('Invalid rootUrl!'); } // Force trailing / on rootUrl, it's easier for us to work with it if (substr($rootUrl, -1) != '/') { $rootUrl .= '/'; } // store rootUrl $this->rootUrl = strstr($rootUrl, '?') ? substr($rootUrl, 0, strpos($rootUrl, '?')) : $rootUrl; // store rootUrl without queryString // If we need to limit to the path of the URL (viz. at first run): take that one into account // Otherwise keep the already set path $this->rootUrlBasePath = $urlParts['scheme'] . '://' . $urlParts['host'] . ($limitToPath ? $urlParts['path'] : $this->rootUrlParts['path']); if (!$limitToPath) { $this->logger->addNotice('Updated rootUrl to ' . $this->rootUrl); $this->logger->addNotice('Updated rootUrlBasePath to ' . $this->rootUrlBasePath); } // store urlParts $this->rootUrlParts = $urlParts; }
/** * Отправляет сообщение в лог * * @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; } }
/** * @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); }
/** * Adds a log record at the EMERGENCY level. * * @param string $message The log message * @param array $context The log context * @return Boolean Whether the record has been processed * @static */ public static function addEmergency($message, $context = array()) { return \Monolog\Logger::addEmergency($message, $context); }
public function emergency($message, array $context = array()) { if (isset($this->logger)) { $this->logger->addEmergency($message, $context); } }
/** * @param string $message * @param array $context * @return bool */ public function addEmergency($message, array $context = array()) { return parent::addEmergency($message, $context); }
public function emergency($msg) { $this->logger->addEmergency($msg); }
/** * @param Logger $logger * @param $msg * @param array $param */ public function emergency(Logger $logger, $msg, $param = array()) { $logger->addEmergency($msg, $param); }
$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();