Skip to content

Commit

Permalink
don't emit empty logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mindplay-dk committed Feb 5, 2019
1 parent 710f7ea commit aa5ba4a
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/ChromeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ public function usePersistence(string $local_path, string $public_path)
*/
public function writeToResponse(ResponseInterface $response)
{
if ($this->local_path) {
$response = $response->withHeader(self::LOCATION_HEADER_NAME, $this->createLogFile());
} else {
$response = $response->withHeader(self::HEADER_NAME, $this->getHeaderValue());
if (count($this->entries)) {
if ($this->local_path) {
$response = $response->withHeader(self::LOCATION_HEADER_NAME, $this->createLogFile());
} else {
$response = $response->withHeader(self::HEADER_NAME, $this->getHeaderValue());
}
}

$this->entries = [];
Expand All @@ -165,17 +167,19 @@ public function writeToResponse(ResponseInterface $response)
*/
public function emitHeader()
{
if (headers_sent()) {
throw new RuntimeException("unable to emit ChromeLogger header: headers have already been sent");
}
if (count($this->entries)) {
if (headers_sent()) {
throw new RuntimeException("unable to emit ChromeLogger header: headers have already been sent");
}

if ($this->local_path) {
header(self::LOCATION_HEADER_NAME . ": " . $this->createLogFile());
} else {
header(self::HEADER_NAME . ": " . $this->getHeaderValue());
}
if ($this->local_path) {
header(self::LOCATION_HEADER_NAME . ": " . $this->createLogFile());
} else {
header(self::HEADER_NAME . ": " . $this->getHeaderValue());
}

$this->entries = [];
$this->entries = [];
}
}

/**
Expand Down

0 comments on commit aa5ba4a

Please sign in to comment.