|
8 | 8 | use Illuminate\Contracts\Foundation\Application;
|
9 | 9 | use Illuminate\Log\LogManager;
|
10 | 10 | use Illuminate\Support\Env;
|
| 11 | +use Monolog\Formatter\JsonFormatter; |
11 | 12 | use Monolog\Handler\NullHandler;
|
| 13 | +use Monolog\Handler\SocketHandler; |
12 | 14 | use Symfony\Component\Console\Output\ConsoleOutput;
|
13 | 15 | use Symfony\Component\ErrorHandler\Error\FatalError;
|
14 | 16 | use Throwable;
|
@@ -52,6 +54,10 @@ public function bootstrap(Application $app)
|
52 | 54 | if (! $app->environment('testing')) {
|
53 | 55 | ini_set('display_errors', 'Off');
|
54 | 56 | }
|
| 57 | + |
| 58 | + if (laravel_cloud()) { |
| 59 | + $this->configureCloudLogging($app); |
| 60 | + } |
55 | 61 | }
|
56 | 62 |
|
57 | 63 | /**
|
@@ -244,6 +250,34 @@ protected function fatalErrorFromPhpError(array $error, $traceOffset = null)
|
244 | 250 | return new FatalError($error['message'], 0, $error, $traceOffset);
|
245 | 251 | }
|
246 | 252 |
|
| 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 | + |
247 | 281 | /**
|
248 | 282 | * Forward a method call to the given method if an application instance exists.
|
249 | 283 | *
|
|
0 commit comments