File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
error_reporting/quickstart Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 7
7
// Imports the Google Cloud client library
8
8
use Google \Cloud \Logging \LoggingClient ;
9
9
10
- // Your Google Cloud Platform project ID
11
- $ projectId = 'YOUR_PROJECT_ID ' ;
10
+ // These variables are set by the App Engine environment. To test locally,
11
+ // ensure these are set or manually change their values.
12
+ $ projectId = getenv ('GCLOUD_PROJECT ' ) ?: 'YOUR_PROJECT_ID ' ;
13
+ $ service = getenv ('GAE_SERVICE ' ) ?: 'error_reporting_quickstart ' ;
14
+ $ version = getenv ('GAE_VERSION ' ) ?: '1.0-dev ' ;
12
15
13
16
// Instantiates a client
14
17
$ logging = new LoggingClient ([
21
24
// Selects the log to write to
22
25
$ logger = $ logging ->logger ($ logName );
23
26
24
- $ handlerFunction = function (Exception $ e ) use ($ logger ) {
27
+ $ handlerFunction = function (Exception $ e ) use ($ logger, $ service , $ version ) {
25
28
// Creates the log entry with the exception trace
26
29
$ entry = $ logger ->entry ([
27
30
'message ' => sprintf ('PHP Warning: %s ' , $ e ),
28
31
'serviceContext ' => [
29
- 'service ' => ' error_reporting_quickstart ' ,
30
- 'version ' => ' 1.0-dev ' ,
32
+ 'service ' => $ service ,
33
+ 'version ' => $ version ,
31
34
]
32
35
]);
33
36
// Writes the log entry
You can’t perform that action at this time.
0 commit comments