Skip to content

Commit 1fc9a4f

Browse files
committed
Make possible to also show the error on your screen
1 parent 3740176 commit 1fc9a4f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Ray PHP error logger
22

3-
Pushes errors that normally would go into the `error.log` or `debug.log` straigh into [Spatie's Ray](https://myray.app) debugger
3+
Pushes errors that normally would go into the `error.log` or `debug.log` straight into [Spatie's Ray](https://myray.app) debugger
44

55
## Installation
66
`composer require jmslbam/ray-php-errors`
77

88
## Activation
9-
Add `( new JMSLBAM\RayPHPErrors\Ray() )->init();` somewhere in your PHP code.
9+
Add `( new JMSLBAM\RayPHPErrors\Ray() )->init( true );` somewhere in your PHP code.
10+
11+
Passing `true` to the `init()` also shows the error on you screen. For example, with WordPress I pass `WP_DEBUG_DISPLAY` as argument.

src/Ray.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
class Ray {
66

7-
public function init() {
7+
/** @var bool */
8+
private $debug;
9+
10+
public function init( $debug = false ) {
11+
12+
$this->debug = $debug;
13+
814
set_exception_handler( [ $this, 'setExceptionHandler'] ); // exception
915
set_error_handler( [ $this, 'setErrorHandler'] ); // error
1016
register_shutdown_function( [ $this, 'registerShutdownFunction'] ); // fatal error
@@ -21,6 +27,10 @@ public function setErrorHandler( $errorNumber, $message, $file, $lineNumber ) {
2127

2228
$this->sendRequest( $message, $file, $lineNumber );
2329

30+
if( $this->debug ) {
31+
dump( $message, $file . ':' . $lineNumber );
32+
}
33+
2434
return false;
2535
}
2636

@@ -39,7 +49,9 @@ public function registerShutdownFunction() {
3949

4050
$this->sendRequest( $error['message'], $error['file'], $error['line'] );
4151

42-
return false;
52+
if( $this->debug ) {
53+
dump( $error );
54+
}
4355
}
4456

4557
/**
@@ -50,8 +62,10 @@ public function registerShutdownFunction() {
5062
public function setExceptionHandler( $exception ) {
5163

5264
$this->sendRequest( $exception->getMessage(), $exception->getFile(), $exception->getLine() );
53-
54-
return false;
65+
66+
if( $this->debug ) {
67+
dump( $exception );
68+
}
5569
}
5670

5771
private function sendRequest( $message, $file, $lineNumber, $color = 'red' ) {

0 commit comments

Comments
 (0)