~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to libphutil/src/channel/PhutilLogfileChannel.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-10-23 20:49:26 UTC
  • mfrom: (0.2.1) (0.1.1)
  • Revision ID: package-import@ubuntu.com-20141023204926-vq80u1op4df44azb
Tags: 0~git20141023-1
Initial release (closes: #703046)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * A @{class:PhutilChannelChannel} which wraps some other channel and writes
 
5
 * data passed over it to a log file.
 
6
 */
 
7
final class PhutilLogfileChannel extends PhutilChannelChannel {
 
8
 
 
9
  private $logfile;
 
10
 
 
11
  public function setLogfile($path) {
 
12
    $this->logfile = fopen($path, 'a');
 
13
    $this->log('--- '.getmypid().' ---');
 
14
    return $this;
 
15
  }
 
16
 
 
17
  public function read() {
 
18
    $buffer = parent::read();
 
19
    $this->log('>>> '.phutil_loggable_string($buffer));
 
20
    return $buffer;
 
21
  }
 
22
 
 
23
  public function write($message) {
 
24
    $this->log('<<< '.phutil_loggable_string($message));
 
25
    return parent::write($message);
 
26
  }
 
27
 
 
28
  private function log($message) {
 
29
    if ($this->logfile) {
 
30
      fwrite($this->logfile, $message."\n");
 
31
    }
 
32
  }
 
33
 
 
34
}