title: How to do advanced filtering of Monolog messages in Symfony?
body: <p>I am using the <code>MonologBundle</code> in my <code>Symfony 2.8</code> project to manage log messages. Using different <code>Handlers</code> it is no problem to write logs to file and to send them by e-mail at the same time.</p>
  
  <p>I would like to reduce the number of messages I receive by mail. I already use the <code>DeduplicationHandler</code> and the <code>FingersCrossed</code> handler to filter by error level and to avoid duplicate messages. This works fine but is not enough. </p>
  
  <p>For example I would like to reduce the number of mail about <code>PageNotFound</code> errors. Of course I want to be notified if <code>/existingPage</code> is not found, but I am not interested in messages about <code>/.well-known/...</code> files. </p>
  
  <p>Another example are messages about errors in a third party CSV parser component. There are several known and harmless errors I am not interested in, but of course other errors are important.</p>
  
  <p>This these errors/messages are generated by third party code, I cannot influence the source. I could only ignore these messages completely but this is not what I want.</p>
  
  <p><strong>I am looking for a solution to filter the messages by content. How can this be done in Monolog?</strong></p>
  
  <p>I already tried to solve this using a <code>HandlerWrapper</code> and discussed this issue in <a href="https://stackoverflow.com/questions/40218472">another question</a>: The idea was, that the <code>HandlerWrapper</code> acts as filter. The <code>HandlerWrapper</code> is called by Monolog, it checks the message content and decides wether it should be processed or not (e.g. discard all messages including the text "./well-known/"). If a messages passes, the <code>HandlerWrapper</code> should simple hand it over to its nested/wrapped handler. Otherwise the message is skipped without further processing. </p>
  
  <p>However this idea did not work, and the answers to the other question indicate, that a <code>HandlerWrapper</code> is not the right approach for this problem. </p>
  
  <p>So the new/actual question is: <strong>How to create a filter for Monolog messages, that let me control wether a specific message should be process or not?</strong></p>