Author: Gabor de Mooij and the RedBeanPHP Community
Inheritance: implements RedBeanPHP\Logger
Example #1
0
 /**
  * Can we manually set a logger and enable logging?
  *
  * @return void
  */
 public function testCanSetLogger()
 {
     R::nuke();
     R::store(R::dispense('bean'));
     $logger = new RDefault();
     $logger->setMode(RDefault::C_LOGGER_ARRAY);
     $database = R::getDatabaseAdapter()->getDatabase();
     $database->setLogger($logger);
     asrt($database->getLogger(), $logger);
     $database->setEnableLogging(FALSE);
     $logs = $logger->getLogs();
     asrt(is_array($logs), TRUE);
     asrt(count($logs), 0);
     $database->setEnableLogging(TRUE);
     $logs = $logger->getLogs();
     asrt(is_array($logs), TRUE);
     asrt(count($logs), 0);
     R::findOne('bean');
     //writes 3 log entries
     $logs = $logger->getLogs();
     asrt(is_array($logs), TRUE);
     asrt(count($logs), 3);
 }
Example #2
0
 /**
  * Toggles DEBUG mode.
  * In Debug mode all SQL that happens under the hood will
  * be printed to the screen or logged by provided logger.
  * If no database connection has been configured using R::setup() or
  * R::selectDatabase() this method will throw an exception.
  * Returns the attached logger instance.
  *
  * @param boolean $tf   debug mode (true or false)
  * @param integer $mode (0 = to STDOUT, 1 = to ARRAY)
  *
  * @return RDefault
  */
 public static function debug($tf = TRUE, $mode = 0)
 {
     if ($mode > 1) {
         $mode -= 2;
         $logger = new Debug();
     } else {
         $logger = new RDefault();
     }
     if (!isset(self::$adapter)) {
         throw new RedException('Use R::setup() first.');
     }
     $logger->setMode($mode);
     self::$adapter->getDatabase()->setDebugMode($tf, $logger);
     return $logger;
 }