0

I run an app on Symfony2. Whenever I load a page or a controller, dev.log file get fill with thousands and thousands with these kind of lines :

[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2017-10-12 15:26:08] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []
[2017-10-12 15:26:09] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2017-10-12 15:26:09] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2017-10-12 15:26:09] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2017-10-12 15:26:09] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2017-10-12 15:26:09] request.INFO: Matched route "getVersion" (parameters: "domain": "BID", "id": "7694", "_controller": "Sii\StimasBundle\Controller\UpdateFolderController::getVersion", "_route": "getVersion") [] []
[2017-10-12 15:26:09] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2017-10-12 15:26:09] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2017-10-12 15:26:09] security.DEBUG: Read SecurityContext from the session [] []
[2017-10-12 15:26:09] security.DEBUG: Reloading user from user provider. [] []
[2017-10-12 15:26:09] doctrine.DEBUG: SELECT t0.username AS username1, t0.username_canonical AS username_canonical2, t0.email AS email3, t0.email_canonical AS email_canonical4, t0.enabled AS enabled5, t0.salt AS salt6, t0
...thousands and thousands of the kind of same lines

Which make the file very very huge over time and it's very annoying.

Here is my config_dev.yml file :

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
#        chromephp:
#            type:  chromephp
#            level: info

assetic:
    use_controller: true

#swiftmailer:
#    delivery_address: me@example.com

What could be the problem and how to get rid of ?

kabrice
  • 1,475
  • 6
  • 27
  • 51

2 Answers2

1

In your config_dev, section monolog, change debug logging level to some higher level, for example, info, or 'error'.

monolog:
  handlers:
    main:
        type: stream
        path: '%kernel.logs_dir%/%kernel.environment%.log'
        level: debug
        channels: ['!event']

You might also want to set up fingers_crossed to save debug messages, but only if error occurs, here is documentation.

Another way is to disable specific error logging channels. Under channels add ['!event', '!doctrine', '!security'] to ignore specific channels: "event", "doctrine", "security" accordingly.

svgrafov
  • 1,970
  • 4
  • 16
  • 32
  • Thank you, I just did that, but it only get rid of `event.DEBUG`. `doctrine.DEBUG`, `security.DEBUG` are still there ! – kabrice Oct 12 '17 at 15:08
  • @kabrice What level you are using now? – svgrafov Oct 12 '17 at 15:11
  • There is another [answer](https://stackoverflow.com/questions/28523211/how-to-disable-security-info-and-security-debug-in-monolog-symfony2-logging) which shows how to disable specific channels, and I like it more. – svgrafov Oct 12 '17 at 15:12
  • I use `level: debug`. On the other hand I'm afraid that if I disable those channels (security, events etc), I could miss some useful debug messages as all debug messages aren't useless. – kabrice Oct 12 '17 at 15:16
  • @kabrice This way only fingers_crossed filter or periodic deletion will help. – svgrafov Oct 12 '17 at 15:18
  • Does it work on Symfony2.2 ? Because I just changed `type: stream` to `type: fingers_crossed` and I get the error : `...Undefined index: handler in /var/www/myproject/vendor/symfony/monolog-bundle...` – kabrice Oct 12 '17 at 15:26
  • @kabrice if you don't want to study the documentation, just change `level: debug` to a higher level like `level: info` – goto Oct 12 '17 at 15:28
  • I just changed `type: stream` to `type: fingers_crossed` and `level: debug` to `level: info` and I got the same error above :( – kabrice Oct 12 '17 at 15:33
  • The `channels: ['!event']` should be better publicised! – 6006604 Jan 28 '21 at 14:27
1

I would leave the debug option enabled as it is and I will go with File Rotation:

# 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

Is what I am using currently and does not bother me at all, that way I can keep the debug messages in case I needed and a fixed amount of files.

Or .... you can mix both solutions if you like.

ReynierPM
  • 17,594
  • 53
  • 193
  • 363