MagratheaPHP2
Up to date Narrative last written —; no source changes since. Method signatures below are reflected live.

Debugger — Debug Mode Manager

File: src/Debugger.php Namespace: Magrathea2 Extends: Singleton

Central debug management for the framework. Controls verbosity of error output, query logging, and stack trace display. Integrates with MagratheaPHP's mode system.


Debug Levels

ConstantValueDescription
Debugger::NONE0No debug output
Debugger::LOG2Log to file only (default)
Debugger::DEBUG3Verbose debug with stack traces
Debugger::DEV4Full development mode

Properties

PropertyTypeDefaultDescription
$logFile?stringnullPath to the debug log file
$debugItemsarray[]Collected debug entries
$debugTypeintLOGCurrent debug level
$queriesboolfalseWhether query logging is enabled

Setting the Debug Level

SetType(int $type): Debugger

Set the debug level manually.

use Magrathea2\Debugger;
Debugger::Instance()->SetType(Debugger::DEV);

SetDev(): Debugger

Enable development mode (level DEV).

Debugger::Instance()->SetDev();

SetDebug(): Debugger

Enable debug mode (level DEBUG).

Debugger::Instance()->SetDebug();

GetType(): int

Returns the current debug level integer.

GetTypeDesc(): string

Returns the current level as a human-readable string.


Query Logging

LogQueries(bool $q): Debugger

Enable or disable SQL query logging.

Debugger::Instance()->LogQueries(true);

When enabled, every SQL query executed via Database is recorded and shown in the debug output.


Adding Debug Items

Add(mixed $debug): void

Add any value to the debug collection (string, array, object).

Debugger::Instance()->Add("Processing user #42");
Debugger::Instance()->Add(["step" => "validation", "passed" => true]);

Info(string $debug): void

Add an info-level string to the debug collection.

Debugger::Instance()->Info("Cache miss for: products_list");

AddError(\Exception $err): void / Error(\Exception $err): void

Record an exception.

try {
    // something risky
} catch (\Exception $e) {
    Debugger::Instance()->AddError($e);
}

AddQuery(string $sql, ?string $values): void

Manually add a query to the debug log.

Debugger::Instance()->AddQuery($sql, json_encode($values));

Displaying Debug Info

Show(): void

Output all collected debug items.

Debugger::Instance()->Show();

Trace(): void

Print the current stack trace.

Debugger::Instance()->Trace();

Log File

SetLogFile(string $file): Debugger

Set a file path for writing debug output.

Debugger::Instance()->SetLogFile("/var/log/myapp/debug.log");

Temporary Level Switching

Useful when you need to temporarily increase verbosity for a specific operation:

SetTemp(string $dType): Debugger

Temporarily switch to a different debug type.

BackTemp(): Debugger

Restore the previous debug type.

$debugger = Debugger::Instance();
$debugger->SetTemp("debug");
// ... do something with more logging ...
$debugger->BackTemp();

Integration with MagratheaPHP Modes

MagratheaPHP methods configure Debugger automatically:

// Dev() → Debugger::DEV, query logging off
MagratheaPHP::Instance()->Dev();

// Debug() → Debugger::DEV, query logging ON
MagratheaPHP::Instance()->Debug();

// Prod() → Debugger::LOG, query logging off
MagratheaPHP::Instance()->Prod();

Example: Request Debug Dump

use Magrathea2\Debugger;

// At the end of a request (dev only)
if (Debugger::Instance()->GetType() >= Debugger::DEV) {
    Debugger::Instance()->Show();
}

Notes

Class Reference — Debugger

Magrathea2\Debugger extends Singleton /home/platypusweb/platypusweb.com.br/site/magratheaphp2/src/Debugger.php

Magrathea Debugger can manage anything for debugging and error-searching through Magrathea Codes. It can trace errors, save log files, print queries and do a bunch of functions that would help the developer on error searching

Add($debug)

Add an item to the debug array object @param string $debug debug item

ParamTypeDefault
$debug mixed required
AddError($err)

Adds an error to the debugger

ParamTypeDefault
$err mixed required
AddQuery($sql, $values)

Adds a query to the debug

ParamTypeDefault
$sql mixed required
$values mixed required
BackTemp()

After temporarily setting a debugging type, gets it back to what it was

Error($err)

Adds an error to the debugger

ParamTypeDefault
$err mixed required
GetType()

Returns the debug type

GetTypeDesc(): string

Returns the debug type in a descritive format

Info($debug)

Add an info item to the debug array object @param string $debug info item

ParamTypeDefault
$debug mixed required
LogQueries($q)

Should debugger log queries?

ParamTypeDefault
$q mixed required
SetDebug()

Sets debug mode as debug

SetDev()

Sets debug mode as dev

SetLogFile($file)

Set the name of log file that will be used (it will be created inside "*logs*" folder)

ParamTypeDefault
$file mixed required
SetTemp($dType)

Sets a debugger type temporarily (usefull when need to check a specific operation, for example)

ParamTypeDefault
$dType mixed required
SetType($type)

Sets the debugger method It can be: *DEV*, *DEBUG*, *LOG*, *NONE* => **Debugger::DEV** = Will print the debugs as it appears in the code **Debugger::DEBUG** = Will store all the debugs and print it later **Debugger::LOG** = Will log queries and other debugs in the code **Debugger::ANALYSIS** = Will return the error with the API **Debugger::NONE** = Well... nothing to do, heh? Default: **LOG**

ParamTypeDefault
$type mixed required
Show()

Prints the debug

Trace()

Trace error location

Examples