Skip to content
Greg Bowler edited this page May 8, 2026 · 2 revisions

phpgt/logger is a small logging library for PHP applications.

Start logging with zero configuration. By default, the logger writes to standard output, so Log::error("You can't do that"); is enough to get started. When we need to, we can configure the logger to write to files, stderr, or any other stream path PHP can open.

The aim of this library is minimalism. There are no large configuration objects, channels, processors, or transport layers to learn first. We get a set of familiar log levels, a tiny handler system, and a straightforward way to route messages where they need to go.

Note

In a WebEngine project, this library is already part of the request lifecycle. WebEngine uses it for request, redirect, timing, and error logging, and configures stdout/stderr handling from the application's logger.* config values. In WebEngine application code, use the Log class statically without needing any configuration.

A small example

use GT\Logger\Log;
use GT\Logger\LogConfig;
use GT\Logger\LogHandler\FileHandler;
use GT\Logger\LogHandler\StdErrHandler;
use GT\Logger\LogLevel;

LogConfig::addHandler(new FileHandler("var/app.log"), LogLevel::DEBUG);
LogConfig::addHandler(new StdErrHandler(), LogLevel::ERROR, LogLevel::EMERGENCY);

Log::info("Application started");
Log::warning("Using fallback configuration");
Log::error("Unable to write cache file", [
	"path" => "var/cache",
]);

This is the core shape of the library: call a static logging method, optionally attach context, and configure handlers once near the start of the application.


To get the first log line on screen and then route it somewhere more useful, read the Quick start guide.

Clone this wiki locally