Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

This example creates two different channels for two different log files and both will be dedicated to their own controllers.


Add monolog bundle to composer.json


"require": {
"symfony/monolog-bundle": "~2.4"
}

Update composer


composer update symfony/monolog-bundle

Update config.yml


Read comment lines below.


monolog:
channels: ["student", "subject"]
handlers:
student:
type: stream
path: %kernel.logs_dir%/%kernel.environment%_student.log # Creates dev_student.log file
channels: ["student"] # Force to handle only student channel
subject:
type: stream
path: %kernel.logs_dir%/%kernel.environment%_subject.log # Creates dev_subject.log file
channels: ["subject"] # Force to handle only subject channel
main:
channels: ["!student", "!subject"] # Force main channel to ignore student and subject channels
console:
channels: ["!doctrine", "!student", "!country"] # Force console channel to ignore student and subject channels as well

StudentController


Class StudentController extends Controller
{
public function indexAction()
{
$this->get('monolog.logger.student')->info('inanzzz info message');
}
}

Result


# app/logs/dev_student.log
[2014-06-07 21:13:18] student.INFO: inanzzz info message [] []

SubjectController


Class StudentController extends Controller
{
public function indexAction()
{
$this->get('monolog.logger.subject')->warning('inanzzz warning message');
}
}

Result


# app/logs/dev_subject.log
[2014-06-07 21:13:18] subject.WARNING: inanzzz warning message [] []