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
 /**
  * Get a collection of loggers to use for logging events.
  *
  * @since 0.1.0
  * @return \Wplog\Logging\LoggerCollection
  */
 public function getLoggerCollection()
 {
     /**
      * Allow filtering the base loggers which Wplog offers.
      *
      * @since 0.1.0
      *
      * @param \Wplog\Logging\LogAdapter[] $loggers Logger instances.
      *
      * @return \Wplog\Logging\LogAdapter[]
      */
     $loggers = apply_filters('wplog/loggers', [new WpdbLogger()]);
     // Rewrap in case someone accidentally forces a single logger through.
     if ($loggers instanceof LogAdapter) {
         trigger_error('Wplog filter `wplog/loggers` is expected to return an array of LogAdapter instances, not a single LogAdapter instance.', E_USER_WARNING);
         $loggers = [$loggers];
     }
     $loggerCollection = new LoggerCollection();
     foreach ($loggers as $logger) {
         $loggerCollection->addLogger($logger);
     }
     return $loggerCollection;
 }