Skip to content

Commit 1b98253

Browse files
committed
adds logging example
1 parent 5f2d7f7 commit 1b98253

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

appengine/standard/logging/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Logging for App Engine (standard)
2+
3+
This app demonstrates how to read App Engine logs. Full instructions at [https://cloud.google.com/appengine/docs/php/logs/](https://cloud.google.com/appengine/docs/php/logs/)

appengine/standard/logging/app.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
runtime: php55
2+
threadsafe: yes
3+
api_version: 1
4+
5+
handlers:
6+
- url: .*
7+
script: index.php
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"google/appengine-php-sdk": "^1.9"
4+
}
5+
}

appengine/standard/logging/composer.lock

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

appengine/standard/logging/index.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
3+
require __DIR__ . '/vendor/autoload.php';
4+
5+
# [START fetch_logs]
6+
use google\appengine\api\log\LogService;
7+
8+
// LogService API usage sample to display application logs for last 24 hours.
9+
$options = [
10+
// Fetch last 24 hours of log data
11+
'start_time' => (time() - (24 * 60 * 60)) * 1e6,
12+
// End time is Now
13+
'end_time' => time() * 1e6,
14+
// Include all Application Logs (i.e. your debugging output)
15+
'include_app_logs' => true,
16+
// Filter out log records based on severity
17+
'minimum_log_level' => LogService::LEVEL_INFO,
18+
];
19+
20+
$logs = LogService::fetch($options);
21+
# [END fetch_logs]
22+
?>
23+
24+
if (empty($logs)): ?>
25+

No logs!

26+
endif ?>
27+
28+
29+
foreach ($logs as $log): ?>
30+

REQUEST LOG

31+
    32+
  • IP: $log->getIp() ?>
  • 33+
  • Status: $log->getStatus() ?>
  • 34+
  • Method: $log->getMethod() ?>
  • 35+
  • Resource: $log->getResource() ?>
  • 36+
  • Date: $log->getEndDateTime()->format('c') ?>
  • 37+
  • 38+
    foreach ($log->getAppLogs() as $app_log): ?>
    39+
    APP LOG
    40+
      41+
    • Message: $app_log->getMessage() ?>
    • 42+
    • Date: $app_log->getDateTime()->format('c') ?>
    • 43+
      44+
      endforeach ?>
      45+
      46+
      47+
      endforeach ?>
      48+

      0 commit comments

      Comments
       (0)