Esempio n. 1
0
 function testItCanWriteLogCollection()
 {
     global $wpdb;
     $collection = new LoggerCollection();
     $collection->addLogger(new WpdbLogger());
     $event = new OptionEvent();
     $event->setBody('Hello World!');
     $event->setSeverity('notice');
     $event->setUserId('1');
     $collection->write($event);
     $row = $wpdb->get_row(sprintf('SELECT * FROM %s.%s', DB_NAME, $wpdb->prefix . 'wplog'));
     $this->assertNotEmpty($row);
     $this->assertStringStartsWith('Hello World', $row->body);
 }
Esempio n. 2
0
 /**
  * Handle and log the events this handler has listened to.
  *
  * @since 0.1.0
  * @access protected
  * @return void
  */
 public function handleEvents()
 {
     if (empty($this->listenerEvents)) {
         return;
     }
     // Prune null events.
     $this->listenerEvents = array_filter($this->listenerEvents, function ($eventObject) {
         return !$eventObject instanceof NullEvent;
     });
     foreach ($this->listenerEvents as $event) {
         try {
             $this->loggerCollection->write($event);
         } catch (\Throwable $t) {
             \Wplog\wplog()->internalLogger()->alert('Could not write log entry: {msg}', ['msg' => $t->getMessage()]);
         }
     }
 }