Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 827
user3396420 Avatar asked Dec 06 '25 20:12

user3396420


1 Answers

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.

like image 119
Igor Pantović Avatar answered Dec 08 '25 12:12

Igor Pantović



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!