redis = $redis; if (!isset($settings)) { $settings = new Settings(); } $this->settings = $settings; } /** * Public method to build a Logger from the singleton Redis client. * * @return static */ public static function createFromGlobals() { $redis = \Redis_Client::getClient(); assert('$redis instanceof \Redis'); return new static($redis); } /** * Logger singleton accessor. * * @return \Redis\Logger\Writer */ public static function instance() { if (!isset(static::$instance)) { static::$instance = static::createFromGlobals(); } return static::$instance; } /** * @param \Redis\Logger\Entry $entry */ protected function post(Entry $entry) { $list = $this->settings->getPrefix() . "{$entry->type}:{$entry->severity}:{$entry->message}"; $item = serialize($entry); $this->redis->lPush($list, $item); } /** * @param \Redis\Logger\Entry $entry */ public function log(Entry $entry) { if ($this->deferred) { $this->entries[] = $entry; } else { $this->post($entry); } } }