Logging by thekid · Pull Request #48 · xp-forge/web

The server logfile can now be controlled. As before, default is to log to standard output, as seen below:

image

Command line

Logging can be controlled via -l command line argument:

$ xp -supervise web -l server.log Service       # Log to server.log
$ xp -supervise web -l - Service                # Log to stdout (explicit)
$ xp -supervise web -l - -l server.log Service  # Log to stdout AND server.log

Inside an application

Regardless of what is passed in via command line:

use web\Application;
use web\log\{ToFile, ToConsole};
use util\log\Logging;

class Service extends Application {

  public function routes() {

    // No logging
    $this->environment->logging()->pipe(null);

    // File
    $this->environment->logging()->pipe(new ToFile('server.log'));

    // Integrate with xp-framework/logging
    $this->environment->logging()->pipe(Logging::all()->toConsole());

    // Multiple targets
    $this->environment->logging()->pipe([new ToFile('server.log'), new ToConsole()]);

    // Log to whatever was given on the command line AND the given target
    $this->environment->logging()->tee(new ToFile('server.log'));
  }
}

See https://en.wikipedia.org/wiki/Tee_(command)
/cc @johannes85