0

I'm using Symfony Commands to run within cron jobs, everything is working fine, except I cannot manage to log anything. Here is my code

namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Psr\Log\LoggerInterface;

class StillSubscriberReminderCommand extends Command
{
    protected static $defaultName = 'app:still_subscriber_reminder';
    private $subscriptionLogger;

    public function __construct(
        LoggerInterface $subscriptionLogger
    )
    {
        $this->logger = $subscriptionLogger;
        parent::__construct();
    }
    protected function configure()
    {
        $this->setDescription('Still subscriber reminder');
    }
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->logger->info('logging test');
        return 0;
    }   
}

Now I've tried calling it commandline:

php /var/app/current/bin/console app:still_subscriber_reminder

But I got nothing within my log file

Also tried running the command via crontab configuration:

* * * * * root php /var/app/current/bin/console app:still_subscriber_reminder

Again nothing I tried to switch verbose level to error:

    $this->logger->error('logging test');

This time, from commandline I can see the error log:

{"message":"logging test","context":{},"level":400,"level_name":"ERROR","channel":"subscription","datetime":"2022-06-28T13:30:52.634581+00:00","extra":{}}
13:30:52 ERROR     [subscription] logging test

But still nothing appear in a log file

Here is my "services.yml" config file, as it seems in can impact how log react from documentation:

parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones
    App\EventListener\RequestListener:
      tags:
        - { name: kernel.event_listener, event: kernel.request }

    App\EventListener\ResponseListener:
      tags:
        - { name: kernel.event_listener, event: kernel.response }
And Row ID
  • 169
  • 11
  • 1
    Logger configuration is done in config/packages/monolog.yaml. Notice that there are different configurations for each environment. I made a quick test of your original code and got the expected info log in var/log/dev.log. – Cerad Jun 28 '22 at 13:51
  • Just switched to "dev" env and got the logs too, it seems in my configuration, production env is not logging, I'll just copy the dev env configuration in the monolog.yaml file ! Thanks for the help, if you want to set an answer mentionning the monolog.yaml file for configuration I would be glad to accept it ! Thanks again – And Row ID Jun 28 '22 at 14:06

0 Answers0