示例#1
0
  /**
   * Logs the message to the log with the given priority.
   *
   * This method only works if the Log Level is higher than the given priority.
   * If there is no logger object than this method will instantiate it.
   * In contrary to the debug statement this only logs strings.
   *
   * @see    DocBlock_Abstract::setLogLevel()
   * @see    Zend_Log
   * @param  string $message
   * @return void
   */
  public function log($message, $priority = Zend_Log::INFO)
  {
    // is the log level is below the priority; just skip this
    if ($this->getLogLevel() < $priority)
    {
      return;
    }

    if ($priority == Zend_Log::DEBUG)
    {
      $this->debug($message);
      return;
    }

    if (!self::$logger)
    {
      $file = str_replace(array('{DATE}'), array(date('YmdHis')), $this->getConfig()->logging->paths->default);

      self::$logger = new Zend_Log(new Zend_Log_Writer_Stream(fopen($file, 'w')));
    }

    static $priority_names = null;
    if ($priority_names === null)
    {
      $r = new ReflectionClass('Zend_Log');
      $priority_names = array_flip($r->getConstants());
    }

    $debug_info = ($this->getLogLevel() == Zend_Log::DEBUG) ? ', '.round(memory_get_usage() / 1024 / 1024, 2).'mb' : '';
    echo '['.$priority_names[$priority].': '.date('H:i').$debug_info.']: '.$message.PHP_EOL;
    self::$logger->log($message, $priority);
  }