jdecool/scaleway-runtimepublic Fork
⑂ 0ac6fa3
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

fix(example): log CRON and Command Invocations without the secretUnverified

In prod without Monolog, Symfony's fallback logger writes to stderr from
the error level only, so the CRON Invocation line never reached Cockpit.
It is lowered to info, and app:greet logs its greeting, as a CRON trigger
drops the Function Response holding the command output. POST / logs the
argument names instead of the body, which holds the CRON secret when a
Command Invocation is rejected.
Jérémy DECOOL committed 2026-11-14T14:37:19+01:00 Browse files
0ac6fa3 parent: 61ed3cb
modified example/config/services.yaml +6 -0
@@ -7,3 +7,9 @@ services:
77 resource: '../src/'
88 exclude:
99 - '../src/Kernel.php'
10+
11+ # Symfony's fallback logger writes to stderr, which reaches Cockpit, but from the error level only:
12+ # lowered to info so the CRON and Command Invocations show up there, without requiring Monolog.
13+ logger:
14+ class: Symfony\Component\HttpKernel\Log\Logger
15+ arguments: ['info']
@@ -7,3 +7,9 @@ services:
7 resource: '../src/'7 resource: '../src/'
8 exclude:8 exclude:
9 - '../src/Kernel.php'9 - '../src/Kernel.php'
10+
11+ # Symfony's fallback logger writes to stderr, which reaches Cockpit, but from the error level only:
12+ # lowered to info so the CRON and Command Invocations show up there, without requiring Monolog.
13+ logger:
14+ class: Symfony\Component\HttpKernel\Log\Logger
15+ arguments: ['info']
modified example/src/Command/GreetCommand.php +7 -0
@@ -2,6 +2,7 @@
22
33 namespace App\Command;
44
5+use Psr\Log\LoggerInterface;
56 use Symfony\Component\Console\Attribute\Argument;
67 use Symfony\Component\Console\Attribute\AsCommand;
78 use Symfony\Component\Console\Attribute\Option;
@@ -12,6 +13,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
1213 #[AsCommand('app:greet', 'Greets someone, or fails on demand to show how a failed command is reported')]
1314 final class GreetCommand
1415 {
16+ public function __construct(private readonly LoggerInterface $logger)
17+ {
18+ }
19+
1520 public function __invoke(
1621 SymfonyStyle $io,
1722 #[Argument] string $name = 'world',
@@ -20,6 +25,8 @@ final class GreetCommand
2025 ): int {
2126 $greeting = \sprintf('Hello %s!', $name);
2227 $io->writeln($yell ? strtoupper($greeting) : $greeting);
28+ // A CRON trigger drops the Function Response holding the output: the log shows the command ran.
29+ $this->logger->info('Command app:greet said: {greeting}', ['greeting' => $greeting]);
2330 if ($fail) {
2431 $io->error('Failing on purpose.');
2532
@@ -2,6 +2,7 @@
2 2
3 namespace App\Command;3 namespace App\Command;
4 4
5+use Psr\Log\LoggerInterface;
5 use Symfony\Component\Console\Attribute\Argument;6 use Symfony\Component\Console\Attribute\Argument;
6 use Symfony\Component\Console\Attribute\AsCommand;7 use Symfony\Component\Console\Attribute\AsCommand;
7 use Symfony\Component\Console\Attribute\Option;8 use Symfony\Component\Console\Attribute\Option;
@@ -12,6 +13,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
12 #[AsCommand('app:greet', 'Greets someone, or fails on demand to show how a failed command is reported')]13 #[AsCommand('app:greet', 'Greets someone, or fails on demand to show how a failed command is reported')]
13 final class GreetCommand14 final class GreetCommand
14 {15 {
16+ public function __construct(private readonly LoggerInterface $logger)
17+ {
18+ }
19+
15 public function __invoke(20 public function __invoke(
16 SymfonyStyle $io,21 SymfonyStyle $io,
17 #[Argument] string $name = 'world',22 #[Argument] string $name = 'world',
@@ -20,6 +25,8 @@ final class GreetCommand
20 ): int {25 ): int {
21 $greeting = \sprintf('Hello %s!', $name);26 $greeting = \sprintf('Hello %s!', $name);
22 $io->writeln($yell ? strtoupper($greeting) : $greeting);27 $io->writeln($yell ? strtoupper($greeting) : $greeting);
28+ // A CRON trigger drops the Function Response holding the output: the log shows the command ran.
29+ $this->logger->info('Command app:greet said: {greeting}', ['greeting' => $greeting]);
23 if ($fail) {30 if ($fail) {
24 $io->error('Failing on purpose.');31 $io->error('Failing on purpose.');
25 32
modified example/src/Controller/DemoController.php +4 -2
@@ -26,9 +26,11 @@ final class DemoController
2626 #[Route('/', methods: ['POST'])]
2727 public function cron(Request $request, LoggerInterface $logger): JsonResponse
2828 {
29- $logger->info('CRON Invocation received', ['body' => $request->getContent()]);
29+ $args = json_decode($request->getContent(), true);
30+ // A body meant as a Command Invocation but rejected lands here: its secret must not reach the logs.
31+ $logger->info('CRON Invocation received with the arguments {keys}', ['keys' => implode(',', array_keys(\is_array($args) ? $args : []))]);
3032
31- return new JsonResponse(['cron' => true, 'args' => json_decode($request->getContent(), true)]);
33+ return new JsonResponse(['cron' => true, 'args' => $args]);
3234 }
3335
3436 #[Route('/hello', methods: ['GET'])]
@@ -26,9 +26,11 @@ final class DemoController
26 #[Route('/', methods: ['POST'])]26 #[Route('/', methods: ['POST'])]
27 public function cron(Request $request, LoggerInterface $logger): JsonResponse27 public function cron(Request $request, LoggerInterface $logger): JsonResponse
28 {28 {
29- $logger->info('CRON Invocation received', ['body' => $request->getContent()]);29+ $args = json_decode($request->getContent(), true);
30+ // A body meant as a Command Invocation but rejected lands here: its secret must not reach the logs.
31+ $logger->info('CRON Invocation received with the arguments {keys}', ['keys' => implode(',', array_keys(\is_array($args) ? $args : []))]);
30 32
31- return new JsonResponse(['cron' => true, 'args' => json_decode($request->getContent(), true)]);33+ return new JsonResponse(['cron' => true, 'args' => $args]);
32 }34 }
33 35
34 #[Route('/hello', methods: ['GET'])]36 #[Route('/hello', methods: ['GET'])]