Manojkumar
Manojkumar

Reputation: 1361

monolog configuration in symfony and customization

I am working on a web app built using Symfony 2.6 and there are different configuration inside app/config folder. How do I know which one is being used. Inside app/config I see config.yml config_dev.yml config_prod.yml and the monolog entry I see in config_dev.yml and also in monolog_prod.yml. It is as below.

monolog:
handlers:
    main:
        type:         fingers_crossed
        action_level: error
        handler:      nested
    nested:
        type:  stream
        path:  "%kernel.logs_dir%/%kernel.environment%.log"
        level: debug
    console:
        type:  console

Now I want to use monolog to input some logs in a controller and put those logs separate form other logs. How can this be done?.

Upvotes: 0

Views: 1924

Answers (1)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

You know which one is used on your environment. If you are in dev mode you are using config_dev.yml merged with config.yml You can check it into your virtual host if the file is on app.php you are in prod mode, if the file points to app_dev.php you are in dev mode usually

To log into other files you can create a channel like this:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      nested
        your_handler:
            level:    debug
            type:     stream
            path:     '%kernel.logs_dir%/custom.log'
            channels: ['your_channel']
        nested:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        console:
            type:  console

And into your controller you can call it in this way:

$logger = $this->get('monolog.logger.your_handler');
$logger->debug('your custom message into your custom log file');

Upvotes: 0

Related Questions