Log levels
The library uses the eight standard PSR-3 level names. They are stored as uppercase constants in GT\Logger\LogLevel, and each one has a matching static method on GT\Logger\Log.
The available levels
DEBUG: detailed debugging informationINFO: interesting events during normal operationNOTICE: normal but significant eventsWARNING: unexpected situations that are not outright failuresERROR: runtime errors that should usually be recorded and investigatedCRITICAL: critical conditionsALERT: action must be taken immediatelyEMERGENCY: the system is unusable
The ordering is important because handler filtering is based on severity. A handler configured with a minimum level of WARNING logs:
WARNINGERRORCRITICALALERTEMERGENCY
but does not log:
DEBUGINFONOTICE
Calling the matching methods
use GT\Logger\Log;
Log::debug("SQL query started");
Log::info("User signed in");
Log::notice("Cache warmup took longer than usual");
Log::warning("Profile picture missing");
Log::error("Could not write session data");
Log::critical("Primary storage unavailable");
Log::alert("Manual intervention required");
Log::emergency("Application cannot continue");
Choosing a minimum level
The minimum level is applied per handler:
use GT\Logger\LogConfig;
use GT\Logger\LogHandler\FileHandler;
use GT\Logger\LogLevel;
LogConfig::addHandler(
new FileHandler("var/error.log"),
LogLevel::ERROR
);
In this example, the handler ignores DEBUG, INFO, NOTICE, and WARNING.
[!NOTE] In WebEngine applications, the configuration of the logger is done by adding settings to the
config.ini.
Choosing a range
addHandler() also accepts an optional maximum level:
LogConfig::addHandler(
new FileHandler("var/normal.log"),
LogLevel::DEBUG,
LogLevel::WARNING
);
This handler receives only the lower-severity messages from DEBUG up to WARNING.
That is useful when we want one output for routine logs and another for errors.
A practical guideline
If we are not sure which level to use, a simple rule of thumb is:
DEBUGwhile inspecting internals during developmentINFOfor ordinary application events we may want to trace laterWARNINGfor something unusual that the application recovered fromERRORwhen the requested operation failed
Once we are consistent about that, handler configuration becomes much easier.
Next: Configuring handlers