laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -0,0 +1,5 @@
disabled:
- align_double_arrow
enabled:
- unalign_double_arrow

View File

@@ -0,0 +1,20 @@
Copyright (c) 2016 Bugsnag
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,14 @@
test:
vendor/bin/phpunit
coverage:
vendor/bin/phpunit --coverage-html=build/coverage
coverage-show:
view-coverage
view-coverage:
open build/coverage/index.html
clean:
rm -rf build/*

View File

@@ -0,0 +1,40 @@
{
"name": "bugsnag/bugsnag-psr-logger",
"type": "library",
"description": "Official Bugsnag PHP PSR Logger.",
"keywords": ["bugsnag", "exceptions", "errors", "logging", "tracking", "psr"],
"homepage": "https://github.com/bugsnag/bugsnag-psr",
"license": "MIT",
"authors": [{
"name": "James Smith",
"email": "notifiers@bugsnag.com",
"homepage": "https://bugsnag.com"
}],
"require": {
"php": ">=5.5",
"bugsnag/bugsnag": "^3.10",
"psr/log": "^1.0|^2.0"
},
"require-dev": {
"graham-campbell/testbench-core": "^1.1",
"mockery/mockery": "^0.9.4|^1.3.1",
"phpunit/phpunit": "^4.8.36|^7.5.15|^9.4.3"
},
"autoload": {
"psr-4" : {
"Bugsnag\\PsrLogger\\" : "src/"
}
},
"autoload-dev": {
"psr-4" : {
"Bugsnag\\PsrLogger\\Tests\\" : "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Bugsnag\PsrLogger;
/**
* @deprecated Use \Psr\Log\AbstractLogger instead
*/
abstract class AbstractLogger extends \Psr\Log\AbstractLogger
{
}

View File

@@ -0,0 +1,203 @@
<?php
namespace Bugsnag\PsrLogger;
use Bugsnag\Client;
use Bugsnag\Report;
use Exception;
use Psr\Log\LogLevel;
use Throwable;
class BugsnagLogger extends AbstractLogger
{
/**
* The bugsnag client instance.
*
* @var \Bugsnag\Client
*/
protected $client;
/**
* The minimum level required to notify bugsnag.
*
* Logs underneath this level will be converted into breadcrumbs.
*
* @var string
*/
protected $notifyLevel = LogLevel::NOTICE;
/**
* Create a new bugsnag logger instance.
*
* @param \Bugsnag\Client $client
*
* @return void
*/
public function __construct(Client $client)
{
$this->client = $client;
}
/**
* Set the notifyLevel of the logger, as defined in Psr\Log\LogLevel.
*
* @param string $notifyLevel
*
* @return void
*/
public function setNotifyLevel($notifyLevel)
{
if (!in_array($notifyLevel, $this->getLogLevelOrder())) {
syslog(LOG_WARNING, 'Bugsnag Warning: Invalid notify level supplied to Bugsnag Logger');
} else {
$this->notifyLevel = $notifyLevel;
}
}
/**
* Log a message to the logs.
*
* @param string $level
* @param mixed $message
* @param array $context
*
* @return void
*/
public function log($level, $message, array $context = [])
{
$title = 'Log '.$level;
if (isset($context['title'])) {
$title = $context['title'];
unset($context['title']);
}
$exception = null;
if (isset($context['exception']) && ($context['exception'] instanceof Exception || $context['exception'] instanceof Throwable)) {
$exception = $context['exception'];
unset($context['exception']);
} elseif ($message instanceof Exception || $message instanceof Throwable) {
$exception = $message;
}
// Below theshold, leave a breadcrumb but don't send a notification
if (!$this->aboveLevel($level, $this->notifyLevel)) {
if ($exception !== null) {
$title = get_class($exception);
$data = ['name' => $title, 'message' => $exception->getMessage()];
} else {
$data = ['message' => $message];
}
$metaData = array_merge($data, $context);
$this->client->leaveBreadcrumb($title, 'log', array_filter($metaData));
return;
}
$severityReason = [
'type' => 'log',
'attributes' => [
'level' => $level,
],
];
if ($exception !== null) {
$report = Report::fromPHPThrowable($this->client->getConfig(), $exception);
} else {
$report = Report::fromNamedError($this->client->getConfig(), $title, $this->formatMessage($message));
}
$report->setMetaData($context);
$report->setSeverity($this->getSeverity($level));
$report->setSeverityReason($severityReason);
$this->client->notify($report);
}
/**
* Checks whether the selected level is above another level.
*
* @param string $level
* @param string $base
*
* @return bool
*/
protected function aboveLevel($level, $base)
{
$levelOrder = $this->getLogLevelOrder();
$baseIndex = array_search($base, $levelOrder);
$levelIndex = array_search($level, $levelOrder);
return $levelIndex >= $baseIndex;
}
/**
* Returns the log levels in order.
*
* @return string[]
*/
protected function getLogLevelOrder()
{
return [
LogLevel::DEBUG,
LogLevel::INFO,
LogLevel::NOTICE,
LogLevel::WARNING,
LogLevel::ERROR,
LogLevel::CRITICAL,
LogLevel::ALERT,
LogLevel::EMERGENCY,
];
}
/**
* Get the severity for the logger.
*
* @param string $level
*
* @return string
*/
protected function getSeverity($level)
{
if ($this->aboveLevel($level, 'error')) {
return 'error';
} elseif ($this->aboveLevel($level, 'warning')) {
return 'warning';
} else {
return 'info';
}
}
/**
* Format the parameters for the logger.
*
* @param mixed $message
*
* @return string
*/
protected function formatMessage($message)
{
if (is_array($message)) {
return var_export($message, true);
}
return $message;
}
/**
* Ensure the given string is less than 100 characters.
*
* @param string $str
*
* @return string
*/
protected function limit($str)
{
if (strlen($str) <= 100) {
return $str;
}
return rtrim(substr($str, 0, 97)).'...';
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Bugsnag\PsrLogger;
class MultiLogger extends AbstractLogger
{
/**
* The registered loggers.
*
* @var \Psr\Log\LoggerInterface[]
*/
protected $loggers;
/**
* Create a new multi logger instance.
*
* @param \Psr\Log\LoggerInterface[] $loggers
*
* @return void
*/
public function __construct(array $loggers)
{
$this->loggers = $loggers;
}
/**
* Log a message to the logs.
*
* @param string $level
* @param mixed $message
* @param array $context
*
* @return void
*/
public function log($level, $message, array $context = [])
{
foreach ($this->loggers as $logger) {
$logger->log($level, $message, $context);
}
}
}