user3396420
user3396420

Reputation: 840

Change log path in Monolog - Symfony2

Currently I've this configuration in config.yml

monolog:
    handlers:
        applog:
            type: stream
            path: /var/log/my_file.log
            level: error

And in my controller, I use:

$logger = $this->get('logger');
$logger->info("test");

But, always this information "test" is writed in /var/log/prod.log

How can I change this to my_file.log?

Thanks

Upvotes: 3

Views: 2705

Answers (1)

Igor Pantović
Igor Pantović

Reputation: 9246

Add channelto your handler config:

monolog:
    handlers:
        applog:
            type: stream
            path: /var/log/my_file.log
            level: error
            channel: my_channel

Now you can get logger service for that channel:

$logger = $this->get('monolog.logger.my_channel');

Furthermore, have in mind that your logging level is error for applog handler so $logger->info will not be visible in file specified. However, $logger->error will be.

Upvotes: 2

Related Questions