Exemple #1
0
 public function testSaveLoad()
 {
     $zmsg = new Zmsg();
     $zmsg->body_set("Hello");
     $zmsg->wrap("address1", "");
     $zmsg->wrap("address2");
     $this->assertEquals($zmsg->parts(), 4);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'w');
     $zmsg->save($fh);
     fclose($fh);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'r');
     $zmsg2 = new Zmsg();
     $zmsg2->load($fh);
     $this->assertEquals($zmsg2->last(), $zmsg->last());
     fclose($fh);
     $this->assertEquals($zmsg2->parts(), 4);
 }
Exemple #2
0
 public function testLoggerWithContext()
 {
     $endpoint = "inproc://zmq_logger2";
     $receiver = $this->createCollector(self::$context, $endpoint);
     $log1 = new ZLogger('l3', $endpoint, self::$context);
     $this->emptyPoll($receiver);
     $collector = new Zmsg($receiver);
     $msgOut = "asd123";
     $context = [1 => 2, 'a' => 'b'];
     $log1->debug($msgOut, $context);
     $collector->recv();
     $this->assertEquals($collector->parts(), 6);
     $this->assertEquals($collector->body(), json_encode($context));
     $this->assertEquals($collector->pop(), 'l3');
     $collector->pop();
     //time
     $this->assertEquals($collector->pop(), 'debug');
     $this->assertEquals($collector->pop(), $msgOut);
     $this->assertEquals($collector->pop(), ZLogger::CONTEXT_DELIMITER);
     $this->assertEquals($collector->pop(), json_encode($context));
 }
Exemple #3
0
 /**
  * @param $level
  * @param $message
  * @param array $context
  * @throws \Exception
  */
 private function send($level, $message, array $context)
 {
     $msg = new Zmsg($this->socket);
     if (sizeof($context) > 0) {
         $msg->wrap(json_encode($context));
         $msg->wrap(ZLogger::CONTEXT_DELIMITER);
     }
     $msg->wrap($message);
     $msg->wrap($level);
     $msg->wrap(sprintf("%.0f", microtime(1) * 1000));
     $msg->wrap($this->logName);
     if ($this->verbose) {
         print_r("I: send msg");
         echo PHP_EOL, $msg, PHP_EOL;
     }
     $msg->send(true);
 }