RedBeanPHP\Logger::log PHP Méthode

log() public méthode

The log method will receive logging data. Note that the number of parameters is 0, this means all parameters are optional and the number may vary. This way the logger can be used in a very flexible way. Sometimes the logger is used to log a simple error message and in other situations sql and bindings are passed. The log method should be able to accept all kinds of parameters and data by using functions like func_num_args/func_get_args.
public log ( ) : void
Résultat void
    public function log();

Usage Example

Exemple #1
0
 /**
  * This method runs the actual SQL query and binds a list of parameters to the query.
  * slots. The result of the query will be stored in the protected property
  * $rs (always array). The number of rows affected (result of rowcount, if supported by database)
  * is stored in protected property $affectedRows. If the debug flag is set
  * this function will send debugging output to screen buffer.
  *
  * @param string $sql      the SQL string to be send to database server
  * @param array  $bindings the values that need to get bound to the query slots
  *
  * @return void
  */
 protected function runQuery($sql, $bindings, $options = array())
 {
     $this->connect();
     if ($this->loggingEnabled && $this->logger) {
         $this->logger->log($sql, $bindings);
     }
     try {
         if (strpos('pgsql', $this->dsn) === 0) {
             if (defined('\\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT')) {
                 $statement = $this->pdo->prepare($sql, array(\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => TRUE));
             } else {
                 $statement = $this->pdo->prepare($sql);
             }
         } else {
             $statement = $this->pdo->prepare($sql);
         }
         $this->bindParams($statement, $bindings);
         $statement->execute();
         $this->queryCounter++;
         $this->affectedRows = $statement->rowCount();
         if ($statement->columnCount()) {
             $fetchStyle = isset($options['fetchStyle']) ? $options['fetchStyle'] : NULL;
             if (isset($options['noFetch']) && $options['noFetch']) {
                 $this->resultArray = array();
                 return $statement;
             }
             $this->resultArray = $statement->fetchAll($fetchStyle);
             if ($this->loggingEnabled && $this->logger) {
                 $this->logger->log('resultset: ' . count($this->resultArray) . ' rows');
             }
         } else {
             $this->resultArray = array();
         }
     } catch (\PDOException $e) {
         //Unfortunately the code field is supposed to be int by default (php)
         //So we need a property to convey the SQL State code.
         $err = $e->getMessage();
         if ($this->loggingEnabled && $this->logger) {
             $this->logger->log('An error occurred: ' . $err);
         }
         $exception = new SQL($err, 0);
         $exception->setSQLState($e->getCode());
         throw $exception;
     }
 }
Logger