8000 backport cloud support · laravel/framework@eab1e93 · GitHub
[go: up one dir, main page]

Skip to content

Commit eab1e93

Browse files
committed
backport cloud support
1 parent d841a22 commit eab1e93

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

src/Illuminate/Console/Scheduling/CommandBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ protected function buildForegroundCommand(Event $event)
3232
{
3333
$output = ProcessUtils::escapeArgument($event->output);
3434

35-
return $this->ensureCorrectUser(
36-
$event, $event->command.($event->shouldAppendOutput ? ' >> ' : ' > ').$output.' 2>&1'
37-
);
35+
return laravel_cloud()
36+
? $this->ensureCorrectUser($event, $event->command.' 2>&1 | tee '.($event->shouldAppendOutput ? '-a ' : '').$output)
37+
: $this->ensureCorrectUser($event, $event->command.($event->shouldAppendOutput ? ' >> ' : ' > ').$output.' 2>&1');
3838
}
3939

4040
/**

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ protected function runCommandInForeground(Container $container)
224224

225225
$this->exitCode = Process::fromShellCommandline(
226226
$this->buildCommand(), base_path(), null, null, null
227-
)->run();
227+
)->run(
228+
laravel_cloud()
229+
? fn ($type, $line) => fwrite($type === 'out' ? STDOUT : STDERR, $line)
230+
: fn () => true
231+
);
228232

229233
$this->callAfterCallbacks($container);
230234
} finally {

src/Illuminate/Foundation/Bootstrap/HandleExceptions.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use Illuminate\Contracts\Debug\ExceptionHandler;
88
use Illuminate\Contracts\Foundation\Application;
99
use Illuminate\Log\LogManager;
10+
use Monolog\Formatter\JsonFormatter;
1011
use Monolog\Handler\NullHandler;
12+
use Monolog\Handler\SocketHandler;
1113
use Symfony\Component\Console\Output\ConsoleOutput;
1214
use Symfony\Component\ErrorHandler\Error\FatalError;
1315
use Throwable;
@@ -51,6 +53,10 @@ public function bootstrap(Application $app)
5153
if (! $app->environment('testing')) {
5254
ini_set('display_errors', 'Off');
5355
}
56+
57+
if (laravel_cloud()) {
58+
$this->configureCloudLogging($app);
59+
}
5460
}
5561

5662
/**
@@ -244,6 +250,34 @@ protected function isFatal($type)
244250
return in_array($type, [E_COMPILE_ERROR, E_CORE_ERROR, E_ERROR, E_PARSE]);
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
* Get an instance of the exception handler.
249283
*

src/Illuminate/Http/Middleware/TrustProxies.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ protected function setTrustedProxyIpAddresses(Request $request)
4949
{
5050
$trustedIps = $this->proxies() ?: config('trustedproxy.proxies');
5151

52-
if (is_null($trustedIps) &&
53-
(($_ENV['LARAVEL_CLOUD'] ?? false) === '1' ||
54-
($_SERVER['LARAVEL_CLOUD'] ?? false) === '1')) {
52+
if (is_null($trustedIps) && laravel_cloud()) {
5553
$trustedIps = '*';
5654
}
5755

src/Illuminate/Support/helpers.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ function filled($value)
146146
}
147147
}
148148

149+
if (! function_exists('laravel_cloud')) {
150+
/**
151+
* Determine if the application is running on Laravel Cloud.
152+
*
153+
* @return bool
154+
*/
155+
function laravel_cloud()
156+
{
157+
return ($_ENV['LARAVEL_CLOUD'] ?? false) === '1' ||
158+
($_SERVER['LARAVEL_CLOUD'] ?? false) === '1';
159+
}
160+
}
161+
149162
if (! function_exists('object_get')) {
150163
/**
151164
* Get an item from an object using "dot" notation.

0 commit comments

Comments
 (0)
0