How to stop Symfony from logging Doctrine's sql queries?

11,004

Solution 1

You should use prod env on your production server. In the prod env doctrine's logging is disabled by default.

But if you want to disable logging at all (in all environments) you need to set up a config.yml like that:

doctrine:
    dbal:
        connections:
            conn1:
                driver: ...
                ...
                logging: false
                profiling: false

Reference: https://symfony.com/doc/current/bundles/DoctrineBundle/configuration.html

Solution 2

I encountered a similar issue with dev.log being generated on prod environment. I figured out from the log entries that what was causing my issue was a scheduled cron job calling a custom symfony command. Modifying the entry to app/console with --env=prod for my crontab since stopped dev.log being generated. i.e.

app/console --env=prod custom:command 

Must have missed that section of the book :)

Share:
11,004

Related videos on Youtube

adit
Author by

adit

Updated on August 29, 2022

Comments

  • adit
    adit over 1 year

    I have a weird issue, when I checked my app/log/dev.log I can see almost all of my queries in my dev.log being logged in real time:

    [2015-01-27 06:57:22] doctrine.DEBUG: SELECT t0.username A ....
    [2015-01-27 06:57:23] doctrine.DEBUG: SELECT t0.username A ...
    [2015-01-27 06:57:23] doctrine.DEBUG: SELECT s0_.id ......
    

    I have no idea why this is happening, since I am running the site on production mode also when I check monolog in my config.yml, this is what I see:

    monolog:
        handlers:
            pictures:
                type: stream
                path: %kernel.logs_dir%/pictures_%kernel.environment%.log
                level: info
            instagram:
                type: stream
                path: %kernel.logs_dir%/instagram_%kernel.environment%.log
                level: info
    

    here's what my config_dev.yml looks like:

    imports:
        - { resource: config.yml }
    
    framework:
        router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }
        profiler: { only_exceptions: false }
    
    web_profiler:
        toolbar: true
        intercept_redirects: false
    
    monolog:
        handlers:
            main:
                type:  stream
                path:  %kernel.logs_dir%/%kernel.environment%.log
                level: debug
            firephp:
                type:  firephp
                level: info
    
    assetic:
        use_controller: false
    
    hip_mandrill:
        disable_delivery: true    
    

    any idea how this could be happening?

  • adit
    adit over 9 years
    I think I am using the prod env on my production server.. I don't want to disable all loggings, just in the prod. If not how can I check that this is the case
  • Michael Sivolobov
    Michael Sivolobov over 9 years
    In prod env you will have logs at app/logs/prod.log
  • adit
    adit over 9 years
    I understand that, however no one seems to be accessing the dev environment, yet the logs are always going there.. I am afraid the prod environment is not really using the prod flag...so how do I check it
  • Michael Sivolobov
    Michael Sivolobov over 9 years
    As I wrote before. You are actually using prod env. You can rename or delete your config_dev.yml and your application will not work. To activate prod env you need to point your web-server to use app.php instead of app_dev.php
  • adit
    adit over 9 years
    I also have another environment, a custom one called app_mobile, but how do I make sure that this is production and not development
  • Michael Sivolobov
    Michael Sivolobov over 9 years
    I don't believe you:-) Post your .htaccess here and your app.php
  • Michael Sivolobov
    Michael Sivolobov over 9 years
    In your front controller (app.php or app_mobile.php) you instantiate AppKernel with two parameters: first argument is a name of your environment (e.g. prod) and the second is debug flag (if true debug-mode will be enabled). The name then is used in filepaths for logs and cache (app/logs/your_env_name_here.log and app/cache/your_env_name_here/)
  • ZhukV
    ZhukV almost 8 years
    If you want disable SQL logging only in one or any actions (not disable in global scope), you can rewrite/drop SQL Logger from Doctrine Configuration: $kernel->getContainer()->get('doctrine.dbal.default_connecti‌​on')->getConfigurati‌​on()->setSQLLogger(n‌​ull);
  • Robert Saylor
    Robert Saylor over 6 years
    Thank you! I discovered my log was 1.7 GB when I found this solution.