Skip to content

Commit a9fe52a

Browse files
author
Takashi Matsuo
authored
Add logging configuration to the laravel sample (GoogleCloudPlatform#557)
* Add logging configuration to the laravel sample * Removed composer.lock
1 parent 01568d4 commit a9fe52a

File tree

9 files changed

+294
-2060
lines changed

9 files changed

+294
-2060
lines changed

appengine/flexible/laravel/app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ env: flex
33

44
runtime_config:
55
document_root: public
6+
enable_stackdriver_integration: true
67

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

1112
env_variables:
1213
# Put production environment variables here.
13-
APP_LOG: errorlog
14+
LOG_CHANNEL: stackdriver
1415
APP_KEY: YOUR_APP_KEY
15-
STORAGE_DIR: /tmp
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Google\Cloud\ErrorReporting\Bootstrap;
7+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
8+
9+
class Handler extends ExceptionHandler
10+
{
11+
/**
12+
* A list of the exception types that are not reported.
13+
*
14+
* @var array
15+
*/
16+
protected $dontReport = [
17+
//
18+
];
19+
20+
/**
21+
* A list of the inputs that are never flashed for validation exceptions.
22+
*
23+
* @var array
24+
*/
25+
protected $dontFlash = [
26+
'password',
27+
'password_confirmation',
28+
];
29+
30+
/**
31+
* Report or log an exception.
32+
*
33+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
34+
*
35+
* @param \Exception $exception
36+
* @return void
37+
*/
38+
// [START stackdriver_exception_handler_configuration ]
39+
public function report(Exception $exception)
40+
{
41+
if (isset($_SERVER['GAE_SERVICE'])) {
42+
Bootstrap::exceptionHandler($exception);
43+
} else {
44+
parent::report($exception);
45+
}
46+
}
47+
// [END stackdriver_exception_handler_configuration ]
48+
49+
/**
50+
* Render an exception into an HTTP response.
51+
*
52+
* @param \Illuminate\Http\Request $request
53+
* @param \Exception $exception
54+
* @return \Illuminate\Http\Response
55+
*/
56+
public function render($request, Exception $exception)
57+
{
58+
return parent::render($request, $exception);
59+
}
60+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
namespace App\Logging;
4+
5+
use Google\Cloud\Logging\LoggingClient;
6+
use Monolog\Handler\PsrHandler;
7+
use Monolog\Logger;
8+
9+
class CreateCustomLogger
10+
{
11+
/**
12+
* Create a custom Monolog instance.
13+
*
14+
* @param array $config
15+
* @return \Monolog\Logger
16+
*/
17+
public function __invoke(array $config)
18+
{
19+
$logName = isset($config['logName']) ? $config['logName'] : 'app';
20+
$psrLogger = LoggingClient::psrBatchLogger($logName);
21+
$handler = new PsrHandler($psrLogger);
22+
$logger = new Logger($logName, [$handler]);
23+
return $logger;
24+
}
25+
}

appengine/flexible/laravel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require-dev": {
3-
"phpunit/phpunit":"~4.8",
3+
"google/cloud-logging": "^1.9",
44
"symfony\/process": "~2.8|~3.0",
55
"monolog\/monolog": "^1.19",
66
"guzzlehttp\/guzzle": "^6.2",

0 commit comments

Comments
 (0)