phasync
Swerve / log

Method

Swerve::log

The log of this process: swerve's own PSR-3 logger, in its format (the time, this worker's slot).

Description#

public static Swerve::log(): LoggerInterface

It writes wherever swerve logs (the terminal, or --log's file), and is a NullLogger with -q. Without swerve's command line (swerve embedded), it is a NullLogger until Swerve::setLog is called. Give it to the libraries that take a PSR-3 logger, or log directly:

Return values#

The log of this process LoggerInterface

Examples#

Example 1The logger before swerve sets one
use Swerve\Swerve;

// Outside swerve's command line, log() is a NullLogger until setLog() is called
echo get_class(Swerve::log()), "\n";
Swerve::log()->error('nobody sees this');

// It is the same object on every call: hand it to libraries that take a PSR-3 logger
var_dump(Swerve::log() === Swerve::log());
Output
Psr\Log\NullLogger
bool(true)
Example 2
Swerve::log()->warning('disk almost full: {free} MB', ['free' => $free]);

See also#

Used in#

  • LaravelRun a Laravel application on Swerve: many requests at once, each in a pooled application of its own.