Beispiel #1
0
 /**
  * {@inheritdoc}
  * @see Scalr\Logger.LoggerStorageInterface::write()
  */
 public function write(LogRecord $record)
 {
     $data = $record->getData();
     $r = array('_id' => $record->getUuid(), 'sessionid' => $record->getSessionid(), 'accountid' => $record->getAccountid(), 'userid' => $record->getUserid(), 'email' => $record->getEmail(), 'envid' => $record->getEnvid(), 'ip' => $record->getIp(), 'time' => new MongoDate($record->getTime()->getTimestamp()), 'message' => $record->getMessage(), 'tags' => $record->getTags()->get(), 'data' => $data instanceof KeyValueRecord ? get_object_vars($data) : array(), 'datatype' => $record->getDatatype());
     return $this->getMongo()->insert($r, array('safe' => $this->options['safe'], 'fsync' => $this->options['fsync'], 'timeout' => $this->options['timeout']));
 }
 /**
  * {@inheritdoc}
  * @see Scalr\Logger.LoggerStorageInterface::write()
  */
 public function write(LogRecord $record)
 {
     $data = $record->getData();
     $this->getDb()->Execute('START TRANSACTION');
     $res = $this->getDb()->Execute("\n            INSERT `auditlog`\n            SET `id` = ?,\n                `sessionid` = ?,\n                `accountid` = ?,\n                `userid` = ?,\n                `email` = ?,\n                `envid` = ?,\n                `ip` = ?,\n                `time` = ?,\n                `message` = ?,\n                `datatype` = ?\n        ", array($record->getUuid(), $record->getSessionid(), $record->getAccountid(), $record->getUserid(), $record->getEmail(), $record->getEnvid(), $record->getIp(), $record->getTime()->format('Y-m-d H:i:s'), $record->getMessage(), $record->getDatatype()));
     if ($res) {
         $stmt = '';
         $rt = array();
         foreach ($record->getTags()->get() as $v) {
             $stmt .= ",('" . $record->getUuid() . "', ?)";
             $rt[] = $v;
         }
         if ($stmt != '') {
             $res = $this->getDb()->Execute("\n                    INSERT `auditlog_tags` (`logid`, `tag`)\n                    VALUES " . substr($stmt, 1) . "\n                ", $rt);
         }
         if ($data instanceof KeyValueRecord) {
             $diff = get_object_vars($data);
             if (!empty($diff)) {
                 $stmt = '';
                 $rt = array();
                 foreach ($diff as $k => $v) {
                     $stmt .= ", ('" . $record->getUuid() . "', ?, ?, ?)";
                     $rt[] = $k;
                     $rt[] = $v['old_value'];
                     $rt[] = $v['new_value'];
                 }
                 if ($stmt != '') {
                     $res = $this->getDb()->Execute("\n                            INSERT `auditlog_data` (`logid`, `key`, `old_value`, `new_value`)\n                            VALUES " . substr($stmt, 1) . "\n                        ", $rt);
                 }
             }
         }
     }
     if ($res) {
         $this->getDb()->Execute('COMMIT');
     } else {
         $this->getDb()->Execute('ROLLBACK');
     }
     return $res ? true : false;
 }