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.levellogger.stderr_levellogger.log_all_requestslogger.log_static_requestslogger.log_redirectslogger.log_404_to_error_log
For the stream split specifically:
logger.leveldefaults todebuglogger.stderr_leveldefaults toERROR
How stdout and stderr are split
During application startup, WebEngine configures:
- the default stdout handler for messages from
logger.levelup to the level belowlogger.stderr_level - a
StdErrHandlerfor messages fromlogger.stderr_levelup toEMERGENCY
So with the default settings:
DEBUG,INFO,NOTICE, andWARNINGgo to stdoutERROR,CRITICAL,ALERT, andEMERGENCYgo 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.