Skip to content

Add logging configuration to the symfony sample #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions appengine/flexible/symfony/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ Before setting up Symfony on App Engine, you will need to complete the following
Use composer to download Symfony Standard and its dependencies

```sh
composer create-project symfony/symfony:^3.0
composer create-project symfony/framework-standard-edition:^3.0
```

# Integrate Stackdriver

Install some cloud libraries for Stackdriver integration

```sh
cd /path/to/symfony
composer require google/cloud-logging google/cloud-error-reporting
```

## Copy over App Engine files
Expand All @@ -29,28 +38,22 @@ directory:
# clone this repo somewhere
git clone https://github.com/GoogleCloudPlatform/php-docs-samples /path/to/php-docs-samples

# copy the two files below to the root directory of your Symfony project
# create a directory for the event subscriber
mkdir -p /path/to/symfony/src/AppBundle/EventSubscriber

# copy the three files below to your Symfony project
cd /path/to/php-docs-samples/appengine/flexible/symfony/
cp ./{app.yaml,nginx-app.conf} /path/to/symfony
cp app.yaml /path/to/symfony
cp app/config/config_prod.yml /path/to/symfony/app/config
cp src/AppBundle/EventSubscriber/ExceptionSubscriber.php \
/path/to/symfony/src/AppBundle/EventSubscriber
```

The two files needed are as follows:
The three files needed are as follows:

1. [`app.yaml`](app.yaml) - The App Engine configuration for your project
1. [`nginx-app.conf`](nginx-app.conf) - Nginx web server configuration needed for `Symfony`

Finally, you need to have a few scripts run after your application deploys.
Add the following scripts to your project's `composer.json`:

```json
{
"scripts": {
"post-install-cmd": [
"chmod -R ug+w $APP_DIR/var"
]
}
}
```
1. [`app/config/config_prod.yml`](app/config/config_prod.yml) - Symfony configurations for Stackdriver Logging
1. [`src/AppBundle/EventSubscriber/ExceptionSubscriber.php`](src/AppBundle/EventSubscriber/ExceptionSubscriber.php) - Symfony configurations for Stackdriver Error Reporting

[1]: https://cloud.google.com/appengine/docs/flexible/
[2]: https://console.cloud.google.com
3 changes: 3 additions & 0 deletions appengine/flexible/symfony/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ env: flex

runtime_config:
document_root: web
front_controller_file: app.php
enable_stackdriver_integration: true

env_variables:
WHITELIST_FUNCTIONS: libxml_disable_entity_loader
SYMFONY_ENV: prod
30 changes: 30 additions & 0 deletions appengine/flexible/symfony/app/config/config_prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
imports:
- { resource: config.yml }

#doctrine:
# orm:
# metadata_cache_driver: apc
# result_cache_driver: apc
# query_cache_driver: apc

monolog:
handlers:
main:
type: fingers_crossed
action_level: debug # Choose whichever level you like
handler: nested
nested:
type: service
id: monolog_psr_batch_logger

services:
# Monolog wrapper
monolog_psr_batch_logger:
class: Monolog\Handler\PsrHandler
arguments: ['@psr_batch_logger']

# PsrBatchLogger
psr_batch_logger:
class: Google\Cloud\Logging\PsrLogger
factory: ['Google\Cloud\Logging\LoggingClient', 'psrBatchLogger']
arguments: ['app']
1 change: 1 addition & 0 deletions appengine/flexible/symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"symfony/process": "^3.0",
"symfony/yaml": "^3.0",
"google/cloud-tools": "^0.6",
"google/cloud-logging": "^1.9",
"paragonie/random_compat": " ^2.0"
}
}
Loading