-
Notifications
You must be signed in to change notification settings - Fork 76
Moved sentry logging to a monolog handler #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8a28d6c
Moved sentry logging to a monolog handler
indykoning f636545
Apply fixes from StyleCI
StyleCIBot 00a5b12
Merge pull request #163 from justbetter/analysis-54MD5B
royduin 61fda24
Codestyle fixes
indykoning c207bb8
Merge branch 'feature/monolog-handler' of github.com:justbetter/magen…
indykoning 7e03caf
Apply fixes from StyleCI
StyleCIBot 9f46233
Merge pull request #164 from justbetter/analysis-YOGZ7y
royduin 4ab0408
Removed explicit type cast
indykoning 90e26bc
Merge branch 'feature/monolog-handler' of github.com:justbetter/magen…
indykoning 8d2722c
Removed expected type for ishandling and handle
indykoning 1b669da
Added a logger api check for backward and forward compatibility
indykoning a195a2b
Check if log level is set before overriding
indykoning 2e31b73
Use prefer lowest and prefer stable for checks, fixed phpstan
indykoning 2a2dbda
Apply fixes from StyleCI
StyleCIBot 107c88e
Merge pull request #166 from justbetter/analysis-01GL4M
royduin 98a7d74
Added dependency on CSP module
indykoning 652527f
Merge branch 'feature/monolog-handler' of github.com:justbetter/magen…
indykoning 28cdf1b
Added monolog context as EventHint
indykoning 62deffc
Apply fixes from StyleCI
StyleCIBot dc344ae
Merge pull request #167 from justbetter/analysis-KonVnA
royduin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace JustBetter\Sentry\Logger\Handler; | ||
|
||
use JustBetter\Sentry\Helper\Data; | ||
use JustBetter\Sentry\Model\SentryLog; | ||
use Magento\Framework\App\DeploymentConfig; | ||
use Monolog\Handler\AbstractHandler; | ||
use Monolog\Logger; | ||
use Monolog\LogRecord; | ||
|
||
// TODO: Remove once V2 support is dropped. | ||
// phpcs:disable Generic.Classes.DuplicateClassName,PSR2.Classes.ClassDeclaration,PSR1.Classes.ClassDeclaration.MultipleClasses | ||
if (Logger::API < 3) { | ||
class Sentry extends AbstractHandler | ||
{ | ||
/** | ||
* Construct. | ||
* | ||
* @param Data $sentryHelper | ||
* @param SentryLog $sentryLog | ||
* @param DeploymentConfig $deploymentConfig | ||
*/ | ||
public function __construct( | ||
protected Data $sentryHelper, | ||
protected SentryLog $sentryLog, | ||
protected DeploymentConfig $deploymentConfig, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isHandling(array $record): bool | ||
{ | ||
$config = $this->sentryHelper->collectModuleConfig(); | ||
if ($config['log_level']) { | ||
$this->setLevel($config['log_level']); | ||
} | ||
|
||
return parent::isHandling($record) && $this->deploymentConfig->isAvailable() && $this->sentryHelper->isActive(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function handle(array $record): bool | ||
{ | ||
if (!$this->isHandling($record)) { | ||
return false; | ||
} | ||
|
||
$this->sentryLog->send($record['message'], $record['level'], $record['context']); | ||
|
||
return false; | ||
} | ||
} | ||
} else { | ||
class Sentry extends AbstractHandler | ||
{ | ||
/** | ||
* Construct. | ||
* | ||
* @param Data $sentryHelper | ||
* @param SentryLog $sentryLog | ||
* @param DeploymentConfig $deploymentConfig | ||
*/ | ||
public function __construct( | ||
protected Data $sentryHelper, | ||
protected SentryLog $sentryLog, | ||
protected DeploymentConfig $deploymentConfig, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isHandling(LogRecord $record): bool | ||
{ | ||
$config = $this->sentryHelper->collectModuleConfig(); | ||
if ($config['log_level']) { | ||
$this->setLevel($config['log_level']); | ||
} | ||
|
||
return parent::isHandling($record) && $this->deploymentConfig->isAvailable() && $this->sentryHelper->isActive(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function handle(LogRecord $record): bool | ||
{ | ||
if (!$this->isHandling($record)) { | ||
return false; | ||
} | ||
|
||
$this->sentryLog->send($record['message'], $record['level'], $record['context']); | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
// phpcs:enable Generic.Classes.DuplicateClassName,PSR2.Classes.ClassDeclaration,PSR1.Classes.ClassDeclaration.MultipleClasses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ parameters: | |
excludePaths: | ||
- vendor | ||
- Test/* | ||
level: 5 | ||
- Logger/Handler/Sentry.php | ||
level: 5 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're housing a version for V2 and V3 PHPStan will never be happy