Skip to content

Logging #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Aug 21, 2018
Merged

Logging #48

merged 20 commits into from
Aug 21, 2018

Conversation

thekid
Copy link
Member

@thekid thekid commented Aug 20, 2018

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

@thekid thekid merged commit f4c2c2a into master Aug 21, 2018
@thekid thekid deleted the feature/logging branch August 21, 2018 12:21
@thekid
Copy link
Member Author

thekid commented Aug 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant