public static function generateLog($e = null, string $level = 'log'): string
    {
        if (ob_get_status()) {
            // Attempt to remove any previous in-progress output buffers
            ob_end_clean();
        }

        ob_start(null, null, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);     // start a new buffer for saving errors

        if ($e instanceof \Throwable) {
            $trace = self::generateCallTrace($e);
            if (!$e instanceof PublicAlert) {
                print '(set_error_handler || set_exception_handler) caught this error. #Bubbled up#' . PHP_EOL;
            } else {
                print 'Public Alert Thrown!' . PHP_EOL;
            }
            print PHP_EOL . $e->getMessage() . PHP_EOL;

        } else {
            $trace = self::generateCallTrace();

            if (\is_array($e) && \count($e) >= 4) {
                print PHP_EOL . 'Carbon caught this Message: ' . $e[1] . PHP_EOL . 'line: ' . $e[2] . '(' . $e[3] . ')' . PHP_EOL;
            }
        }

        print PHP_EOL . $trace . PHP_EOL;

        $output = ob_get_contents();

        ob_end_clean();

        /** @noinspection ForgottenDebugOutputInspection */
        error_log($output);

        if (self::$printToScreen) {
            print "<h1>You have the print to screen Error Catching option turned on!</h1><h2> Turn it off to suppress this reporting.</h2><pre>$output</pre>";
        }

        if (self::$storeReport === true || self::$storeReport === 'file') {       // TODO - store to file?
            if (!is_dir(REPORTS) && !mkdir($concurrentDirectory = REPORTS) && !is_dir($concurrentDirectory)) {
                PublicAlert::danger('Failed Storing Log');
            } else {
                $file = fopen(REPORTS . '/Log_' . time() . '.log', 'ab');

                if (!\is_resource($file) || !fwrite($file, $output)) {
                    PublicAlert::danger('Failed Storing Log');
                }
                fclose($file);
            }
        }

        if (self::$storeReport === true || self::$storeReport === 'database') {       // TODO - store to file?
            $sql = 'INSERT INTO carbon_reports (log_level, report, call_trace) VALUES (?, ?, ?)';
            $sql = Database::database()->prepare($sql);
            if (!$sql->execute([$level, $output, $trace])) {
                print 'Failed to store error log, nothing works... Why does nothing work?' and die(1);
            }
        }

        return $output;
    }
public static function generateLog($e = null, string $level = 'log'): string
    {
        if (ob_get_status()) {
            // Attempt to remove any previous in-progress output buffers
            ob_end_clean();
        }

        ob_start(null, null, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);     // start a new buffer for saving errors

        if ($e instanceof \Throwable) {
            $trace = self::generateCallTrace($e);
            if (!$e instanceof PublicAlert) {
                print '(set_error_handler || set_exception_handler) caught this error. #Bubbled up#' . PHP_EOL;
            } else {
                print 'Public Alert Thrown!' . PHP_EOL;
            }
            print PHP_EOL . $e->getMessage() . PHP_EOL;

        } else {
            $trace = self::generateCallTrace();

            if (\is_array($e) && \count($e) >= 4) {
                print PHP_EOL . 'Carbon caught this Message: ' . $e[1] . PHP_EOL . 'line: ' . $e[2] . '(' . $e[3] . ')' . PHP_EOL;
            }
        }

        print PHP_EOL . $trace . PHP_EOL;

        $output = ob_get_contents();

        ob_end_clean();

        /** @noinspection ForgottenDebugOutputInspection */
        error_log($output);

        if (self::$printToScreen) {
            print "<h1>You have the print to screen Error Catching option turned on!</h1><h2> Turn it off to suppress this reporting.</h2><pre>$output</pre>";
        }

        if (self::$storeReport === true || self::$storeReport === 'file') {       // TODO - store to file?
            if (!is_dir(REPORTS) && !mkdir($concurrentDirectory = REPORTS) && !is_dir($concurrentDirectory)) {
                PublicAlert::danger('Failed Storing Log');
            } else {
                $file = fopen(REPORTS . '/Log_' . time() . '.log', 'ab');

                if (!\is_resource($file) || !fwrite($file, $output)) {
                    PublicAlert::danger('Failed Storing Log');
                }
                fclose($file);
            }
        }

        if (self::$storeReport === true || self::$storeReport === 'database') {       // TODO - store to file?
            $sql = 'INSERT INTO carbon_reports (log_level, report, call_trace) VALUES (?, ?, ?)';
            $sql = Database::database()->prepare($sql);
            if (!$sql->execute([$level, $output, $trace])) {
                print 'Failed to store error log, nothing works... Why does nothing work?' and die(1);
            }
        }

        return $output;
    }
public static function generateLog ( $ e = null , string $ level = 'log' ) : string { if ( ob_get_status ( ) ) { // Attempt to remove any previous in-progress output buffers ob_end_clean ( ) ; } ob_start ( null , null , PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE ) ; // start a new buffer for saving errors if ( $ e instanceof \ Throwable ) { $ trace = self :: generateCallTrace ( $ e ) ; if ( ! $ e instanceof PublicAlert ) { print '(set_error_handler || set_exception_handler) caught this error. #Bubbled up#' . PHP_EOL ; } else { print 'Public Alert Thrown!' . PHP_EOL ; } print PHP_EOL . $ e -> getMessage ( ) . PHP_EOL ; } else { $ trace = self :: generateCallTrace ( ) ; if ( \ is_array ( $ e ) && \ count ( $ e ) >= 4 ) { print PHP_EOL . 'Carbon caught this Message: ' . $ e [ 1 ] . PHP_EOL . 'line: ' . $ e [ 2 ] . '(' . $ e [ 3 ] . ')' . PHP_EOL ; } } print PHP_EOL . $ trace . PHP_EOL ; $ output = ob_get_contents ( ) ; ob_end_clean ( ) ; /** @noinspection ForgottenDebugOutputInspection */ error_log ( $ output ) ; if ( self :: $ printToScreen ) { print "<h1>You have the print to screen Error Catching option turned on!</h1><h2> Turn it off to suppress this reporting.</h2><pre>$output</pre>" ; } if ( self :: $ storeReport === true || self :: $ storeReport === 'file' ) { // TODO - store to file? if ( ! is_dir ( REPORTS ) && ! mkdir ( $ concurrentDirectory = REPORTS ) && ! is_dir ( $ concurrentDirectory ) ) { PublicAlert :: danger ( 'Failed Storing Log' ) ; } else { $ file = fopen ( REPORTS . '/Log_' . time ( ) . '.log' , 'ab' ) ; if ( ! \ is_resource ( $ file ) || ! fwrite ( $ file , $ output ) ) { PublicAlert :: danger ( 'Failed Storing Log' ) ; } fclose ( $ file ) ; } } if ( self :: $ storeReport === true || self :: $ storeReport === 'database' ) { // TODO - store to file? $ sql = 'INSERT INTO carbon_reports (log_level, report, call_trace) VALUES (?, ?, ?)' ; $ sql = Database :: database ( ) -> prepare ( $ sql ) ; if ( ! $ sql -> execute ( [ $ level , $ output , $ trace ] ) ) { print 'Failed to store error log, nothing works... Why does nothing work?' and die ( 1 ) ; } } return $ output ; }
Generate a full error log consisting of a
@param \Throwable|array|null $e
@param string $level
@return string
@internal param $argv
Generate a full error log consisting of a