diff --git a/.travis.yml b/.travis.yml index 030975b163..73a49f78ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,6 +78,11 @@ script: - if [ ${TRAVIS_PHP_VERSION} == '5.5' ]; then composer install; fi; - if [ ${TRAVIS_PHP_VERSION} == '5.5' ]; then env PHP_CGI_PATH=`which php-cgi` LOCAL_TEST_TARGETS='app.yaml backend.yaml' phpunit; fi; - popd + # run compute engine logging tests + - pushd compute/logging + - composer install + - phpunit + - popd after_script: - composer require "satooshi/php-coveralls:^1.0" diff --git a/compute/README.md b/compute/helloworld/README.md similarity index 100% rename from compute/README.md rename to compute/helloworld/README.md diff --git a/compute/app.php b/compute/helloworld/app.php similarity index 100% rename from compute/app.php rename to compute/helloworld/app.php diff --git a/compute/logging/README.md b/compute/logging/README.md new file mode 100644 index 0000000000..21fe81e77a --- /dev/null +++ b/compute/logging/README.md @@ -0,0 +1,3 @@ +# Logging for Compute Engine + +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) diff --git a/compute/logging/composer.json b/compute/logging/composer.json new file mode 100644 index 0000000000..66932a5ba5 --- /dev/null +++ b/compute/logging/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "fluent/logger": "^1.0" + } +} diff --git a/compute/logging/composer.lock b/compute/logging/composer.lock new file mode 100644 index 0000000000..9223167ae7 --- /dev/null +++ b/compute/logging/composer.lock @@ -0,0 +1,72 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "27dad74d408b0b848d82c498ce4cf3ef", + "content-hash": "1ac6bef12b52bca1e2bc43b46f30bc1e", + "packages": [ + { + "name": "fluent/logger", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/fluent/fluent-logger-php.git", + "reference": "360ad86483847f81ba25a79aa183520d790f6fca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fluent/fluent-logger-php/zipball/360ad86483847f81ba25a79aa183520d790f6fca", + "reference": "360ad86483847f81ba25a79aa183520d790f6fca", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.3", + "phpunit/phpunit-mock-objects": "2.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Fluent\\Logger\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache" + ], + "authors": [ + { + "name": "Shuhei Tanuma", + "email": "chobieee@gmail.com" + }, + { + "name": "Sotaro Karasawa", + "email": "sotarok@crocos.co.jp" + }, + { + "name": "DQNEO", + "email": "dqneoo@gmail.com" + } + ], + "description": "a logging library for Fluentd", + "homepage": "http://github.com/fluent/fluent-logger-php", + "keywords": [ + "log", + "logging" + ], + "time": "2015-10-16 05:38:10" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/compute/logging/index.php b/compute/logging/index.php new file mode 100644 index 0000000000..b1a49a8712 --- /dev/null +++ b/compute/logging/index.php @@ -0,0 +1,23 @@ + $e->getMessage(), + 'serviceContext' => array('service' => 'myapp'), + // ... add more metadata + ); + $logger->post('myapp.errors', $msg); +} + +set_exception_handler('fluentd_exception_handler'); +# [END logging] diff --git a/compute/logging/phpunit.xml b/compute/logging/phpunit.xml new file mode 100644 index 0000000000..76410eaec3 --- /dev/null +++ b/compute/logging/phpunit.xml @@ -0,0 +1,31 @@ + + + + + + test + + + + + + + + index.php + + + diff --git a/compute/logging/test/bootstrap.php b/compute/logging/test/bootstrap.php new file mode 100644 index 0000000000..d7d0417d4b --- /dev/null +++ b/compute/logging/test/bootstrap.php @@ -0,0 +1,4 @@ +assertEquals('fluentd_exception_handler', $lastHandler); + + $exceptionMessage = 'testing exception handler'; + $e = new Exception($exceptionMessage); + $lastHandler($e); + $this->assertEquals($logger->prefix, 'myapp.errors'); + $this->assertEquals($exceptionMessage, $logger->msg['message']); + $this->assertEquals($logger->msg['serviceContext'], ['service' => 'myapp']); + } +} diff --git a/compute/logging/test/mocks/FluentLogger.php b/compute/logging/test/mocks/FluentLogger.php new file mode 100644 index 0000000000..8dbaf61ab9 --- /dev/null +++ b/compute/logging/test/mocks/FluentLogger.php @@ -0,0 +1,15 @@ +prefix = $prefix; + $this->msg = $msg; + } +}