Bu örnek iki tane farklı log dosyası yaratmak için, iki tane farklı channel kullanır. Ayrıca farklı controller içinde kullanılırlar.


Monolog paketini composer.json içine ekleme


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

Composer yenileme


composer update symfony/monolog-bundle

Config.yml değişiklikleri


Aşağidaki notları okuyun.


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');
}
}

Sonuç


# 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');
}
}

Sonuç


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