Changeset View
Changeset View
Standalone View
Standalone View
src/channel/PhutilLogFileChannel.php
Show All 10 Lines | final class PhutilLogFileChannel extends PhutilChannelChannel { | ||||
public function setLogfile($path) { | public function setLogfile($path) { | ||||
$this->logfile = fopen($path, 'a'); | $this->logfile = fopen($path, 'a'); | ||||
$this->log('--- '.getmypid().' ---'); | $this->log('--- '.getmypid().' ---'); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function read() { | public function read() { | ||||
$buffer = parent::read(); | $buffer = parent::read(); | ||||
if (strlen($buffer)) { | |||||
$this->log('>>> '.phutil_loggable_string($buffer)); | $this->log('>>> '.phutil_loggable_string($buffer)); | ||||
} | |||||
return $buffer; | return $buffer; | ||||
} | } | ||||
public function write($message) { | public function write($message) { | ||||
if (strlen($message)) { | |||||
$this->log('<<< '.phutil_loggable_string($message)); | $this->log('<<< '.phutil_loggable_string($message)); | ||||
} | |||||
return parent::write($message); | return parent::write($message); | ||||
} | } | ||||
private function log($message) { | private function log($message) { | ||||
if ($this->logfile) { | if ($this->logfile) { | ||||
fwrite($this->logfile, $message."\n"); | fwrite($this->logfile, $message."\n"); | ||||
} | } | ||||
} | } | ||||
} | } |