PHP.GT

WebEngine integration

phpgt/logger is used directly inside WebEngine’s bootstrap and application lifecycle.

That means we can use this package in WebEngine even if we never configure it manually.

What WebEngine uses it for

WebEngine logs several kinds of events through this library, including:

  • request and response status lines
  • redirects
  • slow request timing notices
  • some error conditions
  • optional static-file request logging

[!NOTE] This is one of the reasons the logger stays intentionally small. It is used very early in the lifecycle, before the rest of the application is fully up and running.

The relevant config values

WebEngine reads these logger settings from its application config:

  • logger.level
  • logger.stderr_level
  • logger.log_all_requests
  • logger.log_static_requests
  • logger.log_redirects
  • logger.log_404_to_error_log

For the stream split specifically:

  • logger.level defaults to debug
  • logger.stderr_level defaults to ERROR

How stdout and stderr are split

During application startup, WebEngine configures:

  • the default stdout handler for messages from logger.level up to the level below logger.stderr_level
  • a StdErrHandler for messages from logger.stderr_level up to EMERGENCY

So with the default settings:

  • DEBUG, INFO, NOTICE, and WARNING go to stdout
  • ERROR, CRITICAL, ALERT, and EMERGENCY go to stderr

That makes the default behaviour much more convenient for web servers, containers, and process tools that already treat stdout and stderr differently.

Using the logger in our own WebEngine code

Application code can still call the logger directly:

use GT\Logger\Log;

function do_save():void {
	Log::info("Saving profile");
}

That message goes through the same configured handlers as the framework’s own logging.

One practical implication

LogConfig is static. If we add our own handlers in WebEngine, they are added alongside the framework’s handlers rather than replacing them automatically.

That is usually what we want, but it is worth remembering when a message appears in more than one place.