Skip to content

Commit 669feed

Browse files
committed
adds compute engine logging sample
1 parent 5f2d7f7 commit 669feed

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed
File renamed without changes.
File renamed without changes.

compute/logging/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Logging for Compute Engine
2+
3+
This app demonstrates how to log to Compute Engine from a PHP application. Full instructions at [https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine](https://cloud.google.com/error-reporting/docs/setting-up-on-compute-engine)

compute/logging/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"fluent/logger": "^1.0"
4+
}
5+
}

compute/logging/composer.lock

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

compute/logging/index.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
# [START logging]
4+
require_once __DIR__ . '/vendor/autoload.php';
5+
6+
use Fluent\Logger\FluentLogger;
7+
8+
$logger = new FluentLogger('localhost', '24224');
9+
10+
function fluentd_exception_handler(Exception $e)
11+
{
12+
global $logger;
13+
$msg = array(
14+
'message' => $e->getMessage(),
15+
'serviceContext' => array('service' => 'myapp'),
16+
// ... add more metadata
17+
);
18+
$logger->post('myapp.errors', $msg);
19+
}
20+
21+
set_exception_handler('fluentd_exception_handler');
22+
# [END logging]

0 commit comments

Comments
 (0)