Skip to content

Commit 7793ddf

Browse files
authored
Adds filtered logging URL to php72 logging sample (GoogleCloudPlatform#941)
* fixes cs
1 parent 4edb2e4 commit 7793ddf

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

appengine/php72/logging/index.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright 2018 Google Inc.
45
*
@@ -26,6 +27,28 @@
2627
$logger->warning('This will show up as log level WARNING');
2728
$logger->error('This will show up as log level ERROR');
2829

30+
// Create the proper filter to view the logs in Stackdriver
31+
$projectId = getenv('GOOGLE_CLOUD_PROJECT');
32+
$moduleId = getenv('GAE_SERVICE');
33+
$versionId = getenv('GAE_VERSION');
34+
35+
$resource = sprintf(
36+
'gae_app/module_id/%s/version_id/%s',
37+
$moduleId,
38+
$versionId
39+
);
40+
$logName = sprintf('projects/%s/logs/app', $projectId);
41+
42+
$url = sprintf(
43+
'https://console.cloud.google.com/logs/viewer?resource=%s&logName=%s',
44+
urlencode($resource),
45+
urlencode($logName)
46+
);
47+
2948
?>
3049

31-
Logged INFO, WARNING, and ERROR log levels. Visit console.cloud.google.com/logs to see them
50+
<p>Logged INFO, WARNING, and ERROR log levels. Visit the URL below to see them:</p>
51+
52+
<p><a href="<?= $url ?>"><?= $url ?></a></p>
53+
54+
<?php phpinfo() ?>

0 commit comments

Comments
 (0)