Created
February 10, 2019 08:20
-
-
Save afeld/b02a57c1089295aa2c982cb8d40bec17 to your computer and use it in GitHub Desktop.
StackDriver reporting for PHP CodeIgniter
This file contains 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
<?php | |
use Google\Cloud\ErrorReporting\Bootstrap; | |
use Google\Cloud\Logging\LoggingClient; | |
use Google\Cloud\Core\Report\SimpleMetadataProvider; | |
// application/core/MY_Exceptions.php | |
class MY_Exceptions extends CI_Exceptions { | |
public function __construct() | |
{ | |
parent::__construct(); | |
// set up StackDriver exception handling | |
// https://github.com/GoogleCloudPlatform/php-docs-samples/blob/83cbbeb2ee36a458db4d2dc868cd8e16812fa957/error_reporting/quickstart.php | |
// TODO not in development | |
$projectId = getenv('GCLOUD_PROJECT') ?: 'YOUR_PROJECT_ID'; | |
$service = getenv('GAE_SERVICE') ?: 'testservice'; | |
$version = getenv('GAE_VERSION') ?: 'test'; | |
$logging = new LoggingClient([ | |
'projectId' => $projectId, | |
]); | |
$metadata = new SimpleMetadataProvider([], $projectId, $service, $version); | |
$psrLogger = $logging->psrLogger('error-log', [ | |
'metadataProvider' => $metadata, | |
]); | |
Bootstrap::init($psrLogger); | |
} | |
public function show_exception($exception) | |
{ | |
Bootstrap::exceptionHandler($exception); | |
parent::show_exception($exception); | |
} | |
public function show_php_error($severity, $message, $filepath, $line) | |
{ | |
Bootstrap::errorHandler($severity, $message, $filepath, $line); | |
parent::show_php_error($severity, $message, $filepath, $line); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment