Logging
Set the minimum severity for server messages written to stderr.
Configure log output
logging.level defaults to info and includes messages at that severity and above. Choose debug for TLS handshake diagnostics, warning to suppress routine information, or off to disable logging.
Save one profile as m4w.json and restart the server. Each sample line shows the UTC timestamp, severity, process ID, event name, peer address and any event details.
php vendor/mini4work/webserver/examples/server.php m4w.jsonEach stderr line is a JSON object. Read the severity from level and application fields from context. Before upgrading, replace Logger::write() with a severity method such as Logger::notice(). In 1.9.0 the old call silently skips the event.
Events prefixed with app. are examples emitted by application code. You can write them from a PHP handler.
use M4W\WebServer\Log\Logger;
Logger::notice('app.cache.rebuilt');
Logger::critical('app.database.unavailable');
Logger::alert('app.storage.full');
Logger::emergency('app.service.unavailable');Logging from a PHP service
Save these two files in the application root. The handler calls a service that rebuilds a product index in worker memory. The service records one notice with the number of indexed products.
ProductIndex.php
<?php
use M4W\WebServer\Log\Logger;
final class ProductIndex
{
private array $bySku = [];
public function rebuild(array $products): int
{
$this->bySku = array_column($products, null, 'sku');
$count = count($this->bySku);
Logger::notice('app.cache.rebuilt', ['entries' => $count]);
return $count;
}
}server.php
<?php
use M4W\WebServer\Cli\ServerCommand;
use M4W\WebServer\Http\CallbackRequestHandler;
use M4W\WebServer\Http\Request;
use M4W\WebServer\Http\Response;
require __DIR__.'/vendor/autoload.php';
require __DIR__.'/ProductIndex.php';
$index = new ProductIndex();
$handler = new CallbackRequestHandler(static function (Request $request) use ($index): Response {
if ($request->method !== 'POST' || $request->uri !== '/cache/rebuild') {
return Response::text('Not found', 404);
}
$count = $index->rebuild([['sku' => 'pen'], ['sku' => 'notebook']]);
return Response::json(['entries' => $count]);
});
exit((new ServerCommand)->run($argv, $handler));m4w.json
{
"listen": { "port": 9000 },
"workers": { "count": 1 },
"logging": { "level": "info" }
}php server.php m4w.jsonIn a second terminal, send a request to the loopback listener.
curl -i -X POST http://127.0.0.1:9000/cache/rebuildThe response is HTTP 200 with {"entries":2}. In the server terminal, the service event appears in stderr beside the server’s own request events, with the same worker PID.
{"timestamp":"2026-11-29T16:16:02Z","level":"info","pid":96128,"event":"request.started","ip":"127.0.0.1","context":{"peer":"127.0.0.1:62800","protocol":"HTTP/1.1","method":"POST","path":"/cache/rebuild"}}
{"timestamp":"2026-11-29T16:16:02Z","level":"notice","pid":96128,"event":"app.cache.rebuilt","ip":null,"context":{"entries":2}}
{"timestamp":"2026-11-29T16:16:02Z","level":"info","pid":96128,"event":"request.completed","ip":"127.0.0.1","context":{"peer":"127.0.0.1:62800","protocol":"HTTP/1.1","method":"POST","path":"/cache/rebuild","status":200,"body_length":21,"duration_ms":0.281}}Change the threshold at runtime for current and replacement workers. Check log_level in the status report. A full restart restores the value from m4w.json.
vendor/bin/m4w server:set-log-level warning
vendor/bin/m4w server:status
curl -i -X POST http://127.0.0.1:9000/cache/rebuild
vendor/bin/m4w server:set-log-level infoAt warning, the same request still returns two entries. Its notice event falls below the threshold and disappears from stderr.