123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace Redis\Logger;
- class Writer {
- const PREFIX = 'drupal:logger';
-
- protected $redis;
-
- protected static $instance;
-
- protected $list_limit = NULL;
-
- public $deferred = FALSE;
-
- protected $entries = array();
-
- protected $settings;
-
- protected function __construct(\Redis $redis, Settings $settings = NULL) {
- $this->redis = $redis;
- if (!isset($settings)) {
- $settings = new Settings();
- }
- $this->settings = $settings;
- }
-
- public static function createFromGlobals() {
- $redis = \Redis_Client::getClient();
- assert('$redis instanceof \Redis');
- return new static($redis);
- }
-
- public static function instance() {
- if (!isset(static::$instance)) {
- static::$instance = static::createFromGlobals();
- }
- return static::$instance;
- }
-
- protected function post(Entry $entry) {
- $list = $this->settings->getPrefix() . "{$entry->type}:{$entry->severity}:{$entry->message}";
- $item = serialize($entry);
- $this->redis->lPush($list, $item);
- }
-
- public function log(Entry $entry) {
- if ($this->deferred) {
- $this->entries[] = $entry;
- }
- else {
- $this->post($entry);
- }
- }
- }
|