Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions error_reporting/quickstart/quickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
// Imports the Google Cloud client library
use Google\Cloud\Logging\LoggingClient;

// Your Google Cloud Platform project ID
$projectId = 'YOUR_PROJECT_ID';
// These variables are set by the App Engine environment. To test locally,
// ensure these are set or manually change their values.
$projectId = getenv('GCLOUD_PROJECT') ?: 'YOUR_PROJECT_ID';
$service = getenv('GAE_SERVICE') ?: 'error_reporting_quickstart';
$version = getenv('GAE_VERSION') ?: '1.0-dev';

// Instantiates a client
$logging = new LoggingClient([
Expand All @@ -21,13 +24,13 @@
// Selects the log to write to
$logger = $logging->logger($logName);

$handlerFunction = function (Exception $e) use ($logger) {
$handlerFunction = function (Exception $e) use ($logger, $service, $version) {
// Creates the log entry with the exception trace
$entry = $logger->entry([
'message' => sprintf('PHP Warning: %s', $e),
'serviceContext' => [
'service' => 'error_reporting_quickstart',
'version' => '1.0-dev',
'service' => $service,
'version' => $version,
]
]);
// Writes the log entry
Expand Down