0

I have a Symfony command which is executed under a cron entry and I need some log in production environment.

As I read here in production, for console commands, verbosity level is related to log level shown, so I tried to configure monolog to show "notice" level.

My problem is, log is never written in prod environment.

This is my command:

use Psr\Log\LoggerInterface;
class MyCommand extends Command
{
    private $logger;
    public function __construct(LoggerInterface $logger)
    {
        parent::__construct();
        $this->logger = $logger;
    }
    
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->logger->notice('### HELLO ###');
    }
}

And this is config/packages/prod/monolog.yml, see that action_level is set to notice:

monolog:
    handlers:
        main:
            type: fingers_crossed
            path:  '%kernel.logs_dir%/%kernel.environment%.log'
            action_level: notice
            handler: nested
            excluded_http_codes: [404, 405]
            buffer_size: 50 # How many messages should be saved? Prevent memory leaks
        nested:
            type: stream
            path: php://stderr
            level: debug
            formatter: monolog.formatter.json
        console:
            type: console
            process_psr_3_messages: false
            channels: ["!event", "!doctrine"]

A file var/log/prod.log never appears.

Note: according to this SO answer, commands are always run in dev environment, but the log entries don't appear in dev.log either.

K. Weber
  • 2,643
  • 5
  • 45
  • 77

0 Answers0