PHP errors Catcher module for

v1.2.1 2018-06-05 23:52 UTC

This package is not auto-updated.

Last update: 2021-02-26 09:24:29 UTC


PHP errors Catcher for


  1. Register an account and get an Integration Token.

  2. Install module

Use composer to install Catcher

$ composer require codex-team/hawk.php
  1. Use as a standalone catcher or use with Monolog.

Standalone error catcher

Create an instance with Token at the entry point of your project.


Enable handlers

By default Hawk will catch everything. You can run function with no params.


It's similar to

    TRUE,       // exceptions
    TRUE,       // errors
    TRUE        // shutdown

You can pass types of errors you want to track:

// Catch run-time warnings or compile-time parse errors
    TRUE,                // exceptions
    E_WARNING | E_PARSE, // errors
    TRUE                 // shutdown
// Catch everything except notices
    TRUE,              // exceptions
    E_ALL & ~E_NOTICE, // errors
    TRUE               // shutdown

Catch handled exceptions

You can catch exceptions manually with catchException method.

try {
    throw new Exception("Error Processing Request", 1);
} catch (Exception $e) {

Monolog support

Add a handler to the Monolog. It will catch errors/exception and ignore general logs.

$logger = new \Monolog\Logger('hawk-test');

$HAWK_TOKEN = 'abcd1234-1234-abcd-1234-123456abcdef';
$logger->pushHandler(new \Hawk\Monolog\Handler($HAWK_TOKEN, \Monolog\Logger::DEBUG));

Now you can use logger's functions to process handled exceptions. Pass it to context array in 'exception' field.

try {
   throw new Exception('Something went wrong');
} catch (\Exception $e) {
   $logger->error($e->getMessage(), ['exception' => $e]);

Default error catcher

Register Monolog's handler as catcher.

/** Set monolog as default error handler */
$handler = \Monolog\ErrorHandler::register($logger);

It catches all errors and sends them to Hawk.

Throwing unhandled error example (without try-catch construction):

/** Fatal Error: "Just an error in a high quality code" */
throw new Error('Just an error in a high quality code', E_USER_ERROR);

Issues and improvements

Feel free to ask questions or improve the project.



Report a bug:

Composer Package:

CodeX Team: