Search code examples
phpsymfonymonolog

How to store log messages to specific log file using symfony2


I am new to symfony2, how to store log messages to specific file i read the documentation but i am not understanding please help me any one i configured my config.yml file is:

# app/config/config.yml
monolog:
handlers:
    filter_for_errors:
        type: fingers_crossed
        # if *one* log is error or higher, pass *all* to file_log
        action_level: error
        handler: file_log

    # now passed *all* logs, but only if one log is error or higher
    file_log:
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%.log"

    # still passed *all* logs, and still only logs error or higher
    syslog_handler:
        type: syslog
        level: error

and config_dev file

# app/config/config_dev.yml
    monolog:
    handlers:
    main:
        type:  rotating_file
        path:  '%kernel.logs_dir%/%kernel.environment%.log'
        level: debug
        # max number of log files to keep
        # defaults to zero, which means infinite files
        max_files: 10

if i trying to store log messages using

   $logger = $this->get('logger');
   $logger->info('I just got the logger');

here stores log messages to dev.log file, how to store log messages to easyrecrue.log specific file Thanks for advance


Solution

  • In general, you can create handlers for specific logging channels (like here) to store logs in different files.

    You also need to define your own logging channels.

    Monolog bundle will create services for every channel in a monolog.logger.%your_channel% format.