8000 configure logging for cloud · laravel/framework@3b8ed63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b8ed63

Browse files
committed
configure logging for cloud
1 parent d37ac78 commit 3b8ed63

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/Illuminate/Foundation/Bootstrap/HandleExceptions.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Illuminate\Contracts\Foundation\Application;
99
use Illuminate\Log\LogManager;
1010
use Illuminate\Support\Env;
11+
use Monolog\Formatter\JsonFormatter;
1112
use Monolog\Handler\NullHandler;
13+
use Monolog\Handler\SocketHandler;
1214
use Symfony\Component\Console\Output\ConsoleOutput;
1315
use Symfony\Component\ErrorHandler\Error\FatalError;
1416
use Throwable;
@@ -52,6 +54,10 @@ public function bootstrap(Application $app)
5254
if (! $app->environment('testing')) {
5355
ini_set('display_errors', 'Off');
5456
}
57+
58+
if (laravel_cloud()) {
59+
$this->configureCloudLogging($app);
60+
}
5561
}
5662

5763
/**
@@ -244,6 +250,34 @@ protected function fatalErrorFromPhpError(array $error, $traceOffset = null)
244250
return new FatalError($error['message'], 0, $error, $traceOffset);
245251
}
246252

253+
/**
254+
* Configure the Laravel Cloud log channels.
255+
*
256+
* @param \Illuminate\Contracts\Foundation\Application $app
257+
* @return void
258+
*/
259+
protected function configureCloudLogging(Application $app)
260+
{
261+
$app['config']->set('logging.channels.stderr.formatter_with', [
262+
'includeStacktraces' => true,
263+
]);
264+
265+
$app['config']->set('logging.channels.laravel-cloud-socket', [
266+
'driver' => 'monolog',
267+
'handler' => SocketHandler::class,
268+
'formatter' => JsonFormatter::class,
269+
'formatter_with' => [
270+
'includeStacktraces' => true,
271+
],
272+
'with' => [
273+
'connectionString' => $_ENV['LARAVEL_CLOUD_LOG_SOCKET'] ??
274+
$_SERVER['LARAVEL_CLOUD_LOG_SOCKET'] ??
275+
'unix:///tmp/cloud-init.sock',
276+
'persistent' => true,
277+
],
278+
]);
279+
}
280+
247281
/**
248282
* Forward a method call to the given method if an application instance exists.
249283
*

0 commit comments

Comments
 (0)
0