Skip to content

Commit

Permalink
In PhutilLogFileChannel, don't log empty messages
Browse files Browse the repository at this point in the history
Summary:
Ref T2794. The LogFile channel is used to debug another channel by sending all the messages to a logfile.

We perform empty (zero-length) reads over nonblocking channels in various reasonable situations. Currently, these get written to the logfile as empty lines. However, they are probably never useful.

Instead, only write data if it has nonzero length.

Test Plan: After this change, debugging output from the experimental Phage stuff no longer fills up the protocol logfile with tons of empty messages.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T2794

Differential Revision: https://secure.phabricator.com/D17368
  • Loading branch information
epriestley committed Feb 18, 2017
1 parent 863226f commit 9f66fbd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/channel/PhutilLogFileChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ public function setLogfile($path) {

public function read() {
$buffer = parent::read();
$this->log('>>> '.phutil_loggable_string($buffer));

if (strlen($buffer)) {
$this->log('>>> '.phutil_loggable_string($buffer));
}

return $buffer;
}

public function write($message) {
$this->log('<<< '.phutil_loggable_string($message));
if (strlen($message)) {
$this->log('<<< '.phutil_loggable_string($message));
}

return parent::write($message);
}

Expand Down

0 comments on commit 9f66fbd

Please sign in to comment.