Skip to content

Instantly share code, notes, and snippets.

@mbunge
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbunge/a2c547d49da401a0a0ad to your computer and use it in GitHub Desktop.
Save mbunge/a2c547d49da401a0a0ad to your computer and use it in GitHub Desktop.
Fire http status 500 with Monolog on log level! Usefull when an error occurs.
<?php
/**
*
* @author Marco Bunge <mjls@web.de>
* @copyright 2015 Marco Bunge
* @license http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*
*/
use Monolog\Handler\AbstractHandler;
class HttpErrorHandler extends AbstractHandler
{
/**
* Handles a record.
*
* All records may be passed to this method, and the handler should discard
* those that it does not want to handle.
*
* The return value of this function controls the bubbling process of the handler stack.
* Unless the bubbling is interrupted (by returning true), the Logger class will keep on
* calling further handlers in the stack with a given log record.
*
* @param array $record The record to handle
* @return Boolean true means that this handler handled the record, and that bubbling is not permitted.
* false means the record was either not processed or that this handler allows bubbling.
*/
public function handle(array $record)
{
if ($this->getLevel() >= $record['level']) {
http_response_code(500);
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment