setOptions($options); } return $this; } public function setOptions(array $options = array()) { Qs_Options::setOptions($this, $options); return $this; } public function log($args) { $jsonOptions = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; if (defined('JSON_PARTIAL_OUTPUT_ON_ERROR')) { $jsonOptions |= JSON_PARTIAL_OUTPUT_ON_ERROR; } if (is_array($args)) { $msg = ''; foreach ($args as $arg) { $msg .= ($msg ? ' ' : '') . json_encode($arg, $jsonOptions); } } else { $msg = json_encode($args, $jsonOptions); } $this->getLogger()->log($msg, Zend_Log::INFO); return $this; } public function getFilename() { $filename = rtrim($this->getPath(), '/\\') . '/' . $this->getName() . '.log'; if (false === $this->createPath(dirname($filename))) { throw new \Exception('Can not create logs dir "' . dirname($filename) . '"'); } return $filename; } protected function createPath($logsPath) { if (!is_dir($logsPath)) { $umask = umask(0); if (false === mkdir($logsPath, 0777, true)) { umask($umask); return false; } umask($umask); } return true; } public function getPath() { if (null === $this->path) { $this->path = BASE_PATH . '/tmp/service-logs/' . date('Y-m-d'); } return $this->path; } public function setPath($path) { $this->path = $path; return $this; } public function getName() { if (null === $this->name) { $this->name = 'log'; } return $this->name; } public function setName($name) { $this->name = $name; return $this; } public function getWriter() { if (null === $this->writer) { $this->writer = new Zend_Log_Writer_Stream($this->getFilename()); } return $this->writer; } public function setWriter($writer) { $this->writer = $writer; return $this; } public function getLogger() { if (null === $this->logger) { $this->logger = new Zend_Log($this->getWriter()); } return $this->logger; } public function setLogger($logger) { $this->logger = $logger; return $this; } }