handle = $handle; return $this; } public function hasStream() { return null !== $this->handle; } public function getStream() { if (null === $this->handle) { $this->handle = fopen('php://output', 'w+'); } return $this->handle; } public function isVerbose() { return $this->verbose; } public function setVerbose($verbose) { $this->verbose = $verbose; return $this; } public function getPrefix() { return $this->prefix; } public function setPrefix($prefix) { $this->prefix = $prefix; return $this; } public function log($level, $message, array $context = array()) { $indent = "\t"; $text = date('Y-m-d H:i:s') . $indent . strtoupper($level) . $indent . $this->getPrefix() . Qs_String::fill($message, $context) . PHP_EOL; fwrite($this->getStream(), $text); return $this; } public function removeOldLogs($dir, $limit) { $files = glob($dir . '/*'); sort($files); if (count($files) > $limit) { $removeFiles = array_slice($files, 0, count($files) - $limit); foreach ($removeFiles as $file) { unlink($file); } } return $this; } }