public static function registerErrorHandler(Logger $logger, $continueNativeHandler = false)
    {
        // Only register once per instance
        if (self::$registeredErrorHandler) {
            return false;
        }

        if ($logger === null) {
            throw new \Zend\Log\Exception\InvalidArgumentException('Invalid Logger specified');
        }

        $errorHandlerMap = [
                E_NOTICE => self::NOTICE,
                E_USER_NOTICE => self::NOTICE,
                E_WARNING => self::WARN,
                E_CORE_WARNING => self::WARN,
                E_USER_WARNING => self::WARN,
                E_ERROR => self::ERR,
                E_USER_ERROR => self::ERR,
                E_CORE_ERROR => self::ERR,
                E_RECOVERABLE_ERROR => self::ERR,
                E_STRICT => self::DEBUG,
                E_DEPRECATED => self::DEBUG,
                E_USER_DEPRECATED => self::DEBUG,
        ];

        $previous = set_error_handler(
                function ($errno, $errstr, $errfile, $errline) use (
                $errorHandlerMap, $logger, $continueNativeHandler) {
                    $errorLevel = error_reporting();

                    if ($errorLevel && $errno) {
                        if (isset($errorHandlerMap[$errno])) {
                            $priority = $errorHandlerMap[$errno];
                        } else {
                            $priority = \Zend\Log\Logger::INFO;
                        }
                        $logger->log($priority, 'Error: '.$errstr.' in '.$errfile.' in line '.$errline);

                        return !$continueNativeHandler;
                    }
                });

        register_shutdown_function(
                function () use ($logger) {
                    $error = error_get_last();
                    if (null === $error) {
                        return false;
                    }
                    $priority = \Zend\Log\Logger::ERR;
                    $logger->log($priority, 'Error: '.$error['message'].' in '.$error['file'].' in line '.
                                     $error['line']);
                });

        self::$registeredErrorHandler = true;

        return $previous;
    }