You are here

abstract class Logger in Module Object Oriented Programming API 6.2

Same name in this branch
  1. 6.2 component/decorator/moopapi.logger.inc \Logger
  2. 6.2 component/decorator/logger/moopapi.logger.inc \Logger
Same name and namespace in other branches
  1. 6 component/decorator/moopapi.logger.inc \Logger
  2. 6 component/decorator/logger/moopapi.logger.inc \Logger
  3. 7.2 component/decorator/logger/moopapi.logger.inc \Logger
  4. 7 component/decorator/logger/moopapi.logger.inc \Logger

Logger.

Hierarchy

Expanded class hierarchy of Logger

2 string references to 'Logger'
Application::getAdminForm in component/moopapi.component.inc
Application::submitAdminForm in component/moopapi.component.inc

File

component/decorator/logger/moopapi.logger.inc, line 12

View source
abstract class Logger extends Decorator {
  const LOGGER_DATE_FORMAT = 'Y/m/d H:i:s';

  // A bitmask.
  const LOGGER_DISABLED = 0;
  const LOGGER_FILE = 1;

  // 1 << 0 001
  const LOGGER_DB = 2;

  // 1 << 1 010
  const LOGGER_EMAIL = 4;

  // 1 << 2 100
  protected $date_format;
  protected $destination;
  protected $level;
  public function __construct($decorators_applied = array(), &$relations = array(), $app) {
    parent::__construct($decorators_applied, $relations, $app);
    $this
      ->setLevel(variable_get('botcha_logger_level', self::LOGGER_DISABLED));
    $this
      ->setDestination(variable_get('botcha_logger_destination', LOGGER_DESTINATION));
    $this
      ->setDateFormat(variable_get('botcha_logger_date_format', self::LOGGER_DATE_FORMAT));
  }
  public function setDateFormat($date_format) {
    $this->date_format = $date_format;
  }
  public function getDateFormat() {
    return $this->date_format;
  }
  public function setDestination($destination) {
    $this->destination = $destination;
  }
  public function getDestination() {
    return $this->destination;
  }
  public function setLevel($level) {
    $this->level = $level;
  }
  public function getLevel() {
    return $this->level;
  }
  protected function logCall($method, $arguments) {
    $app = $this->original;
    $class = get_class($app);
    $this
      ->log("!class::!method(!args) <=", array(
      '!class' => $class,
      '!method' => $method,
      '!args' => print_r($arguments, TRUE),
    ));
    $return = call_user_func_array(array(
      $app,
      $method,
    ), $arguments);
    $this
      ->log("!class::!method(!args) return !return", array(
      '!class' => $class,
      '!method' => $method,
      '!args' => print_r($arguments, TRUE),
      '!return' => print_r($return, TRUE),
    ));
    return $return;
  }
  public function log($message, $placeholders = array()) {
    $levels = self::getLevels();
    foreach ($levels as $level) {
      if ($this->level & $level) {
        $this
          ->put2log($message, $placeholders);
      }
    }
  }
  protected static function getLevels() {
    return array(
      self::LOGGER_DISABLED,
      self::LOGGER_FILE,
      self::LOGGER_DB,
      self::LOGGER_EMAIL,
    );
  }
  protected function put2log($message, $placeholders = array()) {
    $destination = NULL;
    $extra_headers = NULL;

    // Match corresponding log levels of error_log function.
    $message_type = 0;
    switch ($this->level) {
      case self::LOGGER_FILE:
        $message_type = 3;
        $destination = $this
          ->getDestination();
        break;
      case self::LOGGER_EMAIL:
        $message_type = 1;

        // @todo Real headers.
        $extra_headers = NULL;
      case self::LOGGER_DB:
      default:

        // Just use default logging behavior.
        break;
    }
    error_log(date($this->date_format, time()) . ' ' . t($message, $placeholders) . "\n", $message_type, $destination, $extra_headers);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Component::$app_name protected property
Component::$decorators_applied protected property
Component::$id protected property
Component::$relations protected property
Component::$rltns protected property
Component::$type protected property 3
Component::ID_APPLICATION constant
Component::TYPE_CONTROLLER constant
Component::TYPE_MODEL constant
Decorator::$original protected property Here the original value of decorated application is stored.
Logger::$date_format protected property
Logger::$destination protected property
Logger::$level protected property
Logger::getDateFormat public function
Logger::getDestination public function
Logger::getLevel public function
Logger::getLevels protected static function
Logger::log public function
Logger::logCall protected function
Logger::LOGGER_DATE_FORMAT constant
Logger::LOGGER_DB constant
Logger::LOGGER_DISABLED constant
Logger::LOGGER_EMAIL constant
Logger::LOGGER_FILE constant
Logger::put2log protected function
Logger::setDateFormat public function
Logger::setDestination public function
Logger::setLevel public function
Logger::__construct public function Overrides Decorator::__construct