0

There are several places in my application where I throw an exception as part of the business logic, but I don't need Symfony2 to generate and log an exception.

For example, when the user attempts an action he can't do temporarily, I call $this->createAccessDeniedException() with a nice error message. This is not an application failure and I don't need it logged. Mostly it's a message to the user saying "try again later, or after you completed this other step first".

Can I teach it to not log certain cases or am I using exceptions badly and if so, what should I do instead?

update: My config:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped
        grouped:
            type:       group
            members:    [streamed, buffered]
        streamed:
            type:       stream
            path:       %kernel.logs_dir%/%kernel.environment%.log
            level:      debug
        buffered:
            type:       buffer
            handler:    swift
        swift:
            type:       swift_mailer
            from_email: xxx@xxx.xxx
            to_email:   xxx@xxx.xxx
            subject:    "Error"
            level:      info
Tom
  • 2,688
  • 3
  • 29
  • 53

1 Answers1

0

As you can see in the ExceptionListener, the AccessDeniedException should not be logged as a normal exception, but as a special message on the DEBUG level.

If you are seeing these messages in your production log files, you should check the minimal level configured for Monolog. I recommend to set it NOTICE.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • see above - I thought I'd already configured it so that it only sends mail on errors. – Tom Jun 01 '14 at 21:12