Skip to content

Add logging configuration to the laravel sample #557

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 2 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
4 changes: 2 additions & 2 deletions appengine/flexible/laravel/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ env: flex

runtime_config:
document_root: public
enable_stackdriver_integration: true

# Ensure we skip ".env", which is only for local development
skip_files:
- .env

env_variables:
# Put production environment variables here.
APP_LOG: errorlog
LOG_CHANNEL: stackdriver
APP_KEY: YOUR_APP_KEY
STORAGE_DIR: /tmp
60 changes: 60 additions & 0 deletions appengine/flexible/laravel/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Exceptions;

use Exception;
use Google\Cloud\ErrorReporting\Bootstrap;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
// [START stackdriver_exception_handler_configuration ]
public function report(Exception $exception)
{
if (isset($_SERVER['GAE_SERVICE'])) {
Bootstrap::exceptionHandler($exception);
} else {
parent::report($exception);
}
}
// [END stackdriver_exception_handler_configuration ]

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
25 changes: 25 additions & 0 deletions appengine/flexible/laravel/app/Logging/CreateCustomLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Logging;

use Google\Cloud\Logging\LoggingClient;
use Monolog\Handler\PsrHandler;
use Monolog\Logger;

class CreateCustomLogger
{
/**
* Create a custom Monolog instance.
*
* @param array $config
* @return \Monolog\Logger
*/
public function __invoke(array $config)
{
$logName = isset($config['logName']) ? $config['logName'] : 'app';
$psrLogger = LoggingClient::psrBatchLogger($logName);
$handler = new PsrHandler($psrLogger);
$logger = new Logger($logName, [$handler]);
return $logger;
}
}
2 changes: 1 addition & 1 deletion appengine/flexible/laravel/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require-dev": {
"phpunit/phpunit":"~4.8",
"google/cloud-logging": "^1.9",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add google/cloud-error-reporting for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's solely for testing. google/cloud-error-reporting is not needed for the test.

"symfony\/process": "~2.8|~3.0",
"monolog\/monolog": "^1.19",
"guzzlehttp\/guzzle": "^6.2",
Expand Down
Loading