PHP.GT

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 information
  • INFO: interesting events during normal operation
  • NOTICE: normal but significant events
  • WARNING: unexpected situations that are not outright failures
  • ERROR: runtime errors that should usually be recorded and investigated
  • CRITICAL: critical conditions
  • ALERT: action must be taken immediately
  • EMERGENCY: 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:

  • WARNING
  • ERROR
  • CRITICAL
  • ALERT
  • EMERGENCY

but does not log:

  • DEBUG
  • INFO
  • NOTICE

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:

  • DEBUG while inspecting internals during development
  • INFO for ordinary application events we may want to trace later
  • WARNING for something unusual that the application recovered from
  • ERROR when the requested operation failed

Once we are consistent about that, handler configuration becomes much easier.


Next: Configuring handlers