本文整理汇总了PHP中Monolog\Logger::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::addError方法的具体用法?PHP Logger::addError怎么用?PHP Logger::addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monolog\Logger
的用法示例。
在下文中一共展示了Logger::addError方法的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: _call
/**
* @param string $token Access token from the calling client
*
* @return string|false The result from the cURL call against the oauth API.
*
* @codeCoverageIgnore This function is not tested because we can't test
* curl_* calls in PHPUnit.
*/
protected function _call($token)
{
$ch = curl_init();
$url = $this->_apiUrl . $token;
$this->_logger->addDebug('calling GET: ' . $url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$result = curl_exec($ch);
$responseCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlErrno = curl_errno($ch);
$curlError = curl_error($ch);
// remove token from url for log output
$url = substr($url, 0, stripos($url, 'token') + 6);
if (0 !== $curlErrno) {
$this->_logger->addError('curl error (' . $curlErrno . '): ' . $curlError . ' url: ' . $url);
}
if ($responseCode >= 500) {
$this->_logger->addError('curl call error: ' . $responseCode . ' url: ' . $url);
} elseif ($responseCode >= 300) {
$this->_logger->addWarning('curl call warning: ' . $responseCode . ' url: ' . $url);
}
$this->_logger->addDebug('result: (' . $responseCode . ') ' . var_export($result, true));
curl_close($ch);
return $result;
}
示例3: writeEntry
protected function writeEntry($level, $message, $indent, $category = "", $additionalData = [])
{
$message = str_pad($category, 16, " ", STR_PAD_RIGHT) . "\t" . str_repeat(" ", $indent) . $message;
switch ($level) {
case Log::BULK_DATA_LEVEL:
$this->logger->addDebug($message, $additionalData);
break;
case Log::DEBUG_LEVEL:
$this->logger->addDebug($message, $additionalData);
break;
case Log::ERROR_LEVEL:
$this->logger->addError($message, $additionalData);
break;
case Log::PERFORMANCE_LEVEL:
$this->logger->addNotice($message, $additionalData);
break;
case Log::WARNING_LEVEL:
$this->logger->addWarning($message, $additionalData);
break;
case Log::REPOSITORY_LEVEL:
$this->logger->addNotice($message, $additionalData);
break;
default:
$this->logger->addNotice($message, $additionalData);
}
}
示例4: exceptionHandler
public function exceptionHandler(\Exception $exception)
{
#Send the error to the log file
// these are our templates
$traceline = "#%s %s(%s): %s(%s)" . PHP_EOL;
$msg = "\n\n PHP Fatal error: Uncaught exception '%s' with message '%s' in %s:%s\nStack trace:\n%s\n Thrown in %s on line %s \n\n";
// alter your trace as you please, here
$trace = $exception->getTrace();
foreach ($trace as $key => $stackPoint) {
// I'm converting arguments to their type
// (prevents passwords from ever getting logged as anything other than 'string')
$trace[$key]['args'] = \array_map('gettype', $trace[$key]['args']);
}
// build your tracelines
$result = array();
$key = 0;
foreach ($trace as $key => $stackPoint) {
$result[] = \sprintf($traceline, $key, $stackPoint['file'], $stackPoint['line'], $stackPoint['function'], \implode(', ', $stackPoint['args']));
$key = $key;
}
// trace always ends with {main}
$result[] = '#' . ++$key . ' {main}';
// write tracelines into main template
$msg = \sprintf($msg, \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), \implode("\n", $result), $exception->getFile(), $exception->getLine());
#write to log
$this->log->addError($msg);
# log to console
$this->output->writeln('<error>' . $msg . '</error>');
}
示例5: write
/**
* Uses the Monolog file Logger to write a log message in a file.
*
* @param string $message Message that needs to be output
* @param bool $error If the log message is considered an error, for logging purposes
*/
public function write($message, $error = false)
{
if (!$error) {
$this->logger->addWarning($message);
return;
}
$this->logger->addError($message);
}
示例6: __invoke
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
if ($next) {
$this->logger->addError('Bar', ['next' => true]);
$response = $next($request, $response);
}
return $response;
}
示例7: saveToDisk
/**
*
* @param \Exception $objEx
*/
public function saveToDisk(\Exception $objEx)
{
try {
$this->logger->addError(Carbon::now()->toDateTimeString() . ' : ' . $objEx->getTraceAsString());
} catch (\Exception $e) {
$this->push($e);
}
$this->push($objEx);
}
示例8: run
public function run()
{
$configFile = tempnam(sys_get_temp_dir(), 'satis-admin');
file_put_contents($configFile, $this->manager->getJson());
$process = ProcessBuilder::create(['php', $this->binDir . '/satis', 'build', $configFile, $this->outputDir])->getProcess();
$this->logger->addInfo('Building config...', ['command-line' => $process->getCommandLine()]);
if (0 === $process->run()) {
$this->logger->addInfo('Config built.');
} else {
$this->logger->addError('Config not build', ['stdout' => $process->getOutput(), 'stderr' => $process->getErrorOutput()]);
}
}
示例9: post
/**
* @param String $url
* @param array $parameters
* @param array $headers
* @return mixed
*/
public function post(string $url, $parameters = array(), $headers = array())
{
$headers = array_merge($headers, ["Connection: keep-alive", "Keep-Alive: timeout=10, max=1000", "Content-Type: application/x-www-form-urlencoded"]);
try {
$curl = curl_init();
curl_setopt_array($curl, [CURLOPT_USERAGENT => "Sovereign Discord Bot", CURLOPT_TIMEOUT => 8, CURLOPT_FORBID_REUSE => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_POSTFIELDS => http_build_query($parameters)]);
$result = curl_exec($curl);
return $result;
} catch (\Exception $e) {
$this->log->addError("There was an error using cURL: ", [$e->getMessage()]);
}
}
示例10: run
public function run()
{
$configFile = tempnam($this->cacheDir . '/satis', 'satis-admin');
file_put_contents($configFile, $this->manager->getJson());
$process = ProcessBuilder::create(['php', $this->binDir . '/satis', 'build', $configFile, $this->outputDir])->setTimeout(null)->addEnvironmentVariables(['HOME' => $this->cacheDir])->getProcess();
$this->logger->addInfo('Building config...', ['command-line' => $process->getCommandLine()]);
if (0 === $process->run()) {
unlink($configFile);
$this->logger->addInfo('Config built.');
} else {
$this->logger->addError('Config not build', ['stdout' => $process->getOutput(), 'stderr' => $process->getErrorOutput()]);
}
}
示例11: loadFile
/**
* @param $configFile
*/
public function loadFile($configFile)
{
if (!file_exists(realpath($configFile))) {
$this->logger->addError('Config file ' . realpath($configFile) . ' not found.');
return;
}
try {
$this->config = array_change_key_case(include $configFile, \CASE_LOWER);
$this->logger->addDebug('Config file loaded: ' . realpath($configFile));
} catch (\Exception $e) {
$this->logger->addError('Failed loading config file (' . realpath($configFile) . '): ' . $e->getMessage());
}
}
示例12: run
public function run(Message $message, Discord $discord, WebSocket $webSocket, Logger $log, &$audioStreams, Channel $channel, cURL $curl)
{
$exp = explode(" ", $message->content);
unset($exp[0]);
$youtubeLink = implode(" ", $exp);
// URL Checker
$parts = parse_url($youtubeLink);
if (!stristr($parts["host"], "youtube.com")) {
return $message->reply("Error, you can only use youtube links!");
}
// Generate song md5
$md5 = md5($youtubeLink);
// Now get the mp3 from the cache
$songFile = __DIR__ . "/../../../../../cache/songs/{$md5}.mp3";
$dl = new YoutubeDl(["extract-audio" => true, "audio-format" => "mp3", "audio-quality" => 0, "output" => $songFile]);
$title = "";
try {
$video = $dl->download($youtubeLink);
$title = $video->getTitle();
$log->addNotice("Downloading {$title} from YouTube");
} catch (NotFoundException $e) {
$log->addError("Error: the song was not found: {$e->getMessage()}");
$message->reply("Error: the song was not found: {$e->getMessage()}");
} catch (PrivateVideoException $e) {
$log->addError("Error: song has been made private: {$e->getMessage()}");
$message->reply("Error: song has been made private: {$e->getMessage()}");
} catch (CopyrightException $e) {
$log->addError("Error: song is under copyright: {$e->getMessage()}");
$message->reply("Error: song is under copyright: {$e->getMessage()}");
} catch (\Exception $e) {
$log->addError("Error: {$e->getMessage()}");
$message->reply("Error: {$e->getMessage()}");
}
$webSocket->joinVoiceChannel($channel)->then(function (VoiceClient $vc) use($message, $discord, $webSocket, $log, &$audioStreams, $channel, $curl, $songFile, $title) {
$guildID = $message->getChannelAttribute()->guild_id;
if (file_exists($songFile)) {
// Add this audio stream to the array of audio streams
$audioStreams[$guildID] = $vc;
$vc->setFrameSize(40)->then(function () use($vc, &$audioStreams, $guildID, $songFile, $log, $message, $title, $channel) {
$vc->setBitrate(128000);
$message->reply("Now playing **{$title}** in {$channel->name}");
$vc->playFile($songFile, 2)->done(function () use($vc, &$audioStreams, $guildID) {
unset($audioStreams[$guildID]);
$vc->close();
});
});
}
});
}
示例13: format
/**
* format - prune the registry based on xml config
*
* @param string XMLpath
* @param Registry registry
*
* @return array
*/
public static function format(YAMLConfiguration $params, HTTPRequest $request, HTTPResponse &$response, Logger $logger)
{
$attributes = $request->getAttributes();
$output = array();
if (count($params) < 1) {
if (self::PARANOID_MODE) {
$logger->addError('XML is missing CherryPicker configs for ' . $uri);
throw new XMLNodeNotConfiguredException('need to customize error for YAML configs for ' . $uri);
}
//not paranoid? ok - dump the whole registry to the user
foreach ($attributes as $key => $value) {
$output[self::trimNamespacing($key)] = $attributes[$key];
}
return $output;
}
$configs = array_filter($params->getConfigs());
foreach ($configs as $key => $outputSet) {
// pr($outputSet);
// exit;
foreach ($outputSet as $className => $columns) {
if (is_array($outputSet)) {
self::formatArray($className, $columns, $output, $attributes, $logger);
}
}
}
$response = new HTTPResponse($output);
}
示例14: __invoke
/**
* Called when this object is called as a function
*
* @param Context $context
* @param OptionsFactory $optionsFactory
* @throws \Exception if haltOnError setting is true
*/
public function __invoke(Context $context, OptionsFactory $optionsFactory)
{
$getopt = $context->getopt(array_keys(self::$options));
// Get directory list
$dirListFactory = new DirectoryListFactory();
$dirListFactory->loadFromCommandline($getopt->get(), 2);
$dirListFactory->loadFromStdin(new StdinReader(3));
$dirList = $dirListFactory->getList();
$this->logger->addDebug('Found directories', [count($dirList)]);
// Load base options
$baseOptions = $optionsFactory->newInstance();
$baseOptions->validateAllRequired();
if ($baseOptions->preview) {
$this->logger->addNotice('PREVIEW MODE');
}
foreach ($dirList as $dir) {
try {
$this->logger->addNotice('In directory', [$dir]);
$this->processDirectory($dir, $baseOptions, $optionsFactory);
} catch (\Exception $e) {
if ($baseOptions->haltOnError) {
throw $e;
} elseif ($baseOptions->verbosity == 2) {
$this->logger->addError($e, []);
} else {
$this->logger->addError($e->getMessage(), []);
}
}
}
}
示例15: sendRequest
private function sendRequest($url, $method, $request)
{
try {
if (strtoupper($method) == 'GET') {
$this->logger->debug("Sending GET request to {$url}, query=" . json_encode($request));
$reply = $this->httpClient->get($url, ['query' => $request]);
} else {
$this->logger->debug("Sending {$method} request to {$url}, body=" . json_encode($request));
$reply = $this->httpClient->send($this->httpClient->createRequest($method, $url, ['body' => json_encode($request)]));
}
} catch (RequestException $e) {
//Stash error: it can't send more then 1mb of json data. So just skip suck pull requests or files
$this->logger->debug("Request finished with error: " . $e->getMessage());
if ($e->getMessage() == 'cURL error 56: Problem (3) in the Chunked-Encoded data') {
throw new Exception\StashJsonFailure($e->getMessage(), $e->getRequest(), $e->getResponse(), $e);
} else {
throw $e;
}
}
$this->logger->debug("Request finished");
$json = (string) $reply->getBody();
//an: пустой ответ - значит все хорошо
if (empty($json)) {
return true;
}
$data = json_decode($json, true);
if ($data === null && $data != 'null') {
$this->logger->addError("Invalid json received", ['url' => $url, 'method' => $method, 'request' => $request, 'reply' => $json]);
throw new \Exception('invalid_json_received');
}
return $data;
}