You are here

abstract class UltimateCronLogger in Ultimate Cron 7.2

Abstract class for Ultimate Cron loggers.

Each logger must implement its own functions for getting/setting data from the its storage backend.

Abstract methods: load($name, $lock_id = NULL)

  • Load a log entry. If no $lock_id is provided, this method should load the latest log entry for $name.

"Abstract" properties: $log_entry_class

  • The class name of the log entry class associated with this logger.

Hierarchy

Expanded class hierarchy of UltimateCronLogger

4 string references to 'UltimateCronLogger'
cache.inc in plugins/ultimate_cron/logger/cache.inc
database.inc in plugins/ultimate_cron/logger/database.inc
ultimate_cron_ctools_plugin_type in ./ultimate_cron.module
Implements hook_ctools_plugin_type().
ultimate_cron_watchdog in ./ultimate_cron.module
Implements hook_watchdog().

File

./ultimate_cron.plugin.inc, line 1165
Plugin framework for Ultimate Cron.

View source
abstract class UltimateCronLogger extends UltimateCronPlugin {
  public static $log_entries = NULL;
  public $log_entry_class = 'UltimateCronLogEntry';

  /**
   * Factory method for creating a new unsaved log entry object.
   *
   * @param string $name
   *   Name of the log entry (name of the job).
   *
   * @return UltimateCronLogEntry
   *   The log entry.
   */
  public function factoryLogEntry($name) {
    return new $this->log_entry_class($name, $this);
  }

  /**
   * Create a new log entry.
   *
   * @param string $name
   *   Name of the log entry (name of the job).
   * @param string $lock_id
   *   The lock id.
   * @param string $init_message
   *   (optional) The initial message for the log entry.
   *
   * @return UltimateCronLogEntry
   *   The log entry created.
   */
  public function create($name, $lock_id, $init_message = '', $log_type = ULTIMATE_CRON_LOG_TYPE_NORMAL) {
    $log_entry = new $this->log_entry_class($name, $this, $log_type);
    $log_entry->lid = $lock_id;
    $log_entry->start_time = microtime(TRUE);
    $log_entry->init_message = $init_message;
    $log_entry
      ->save();
    return $log_entry;
  }

  /**
   * Begin capturing messages.
   *
   * @param UltimateCronLogEntry $log_entry
   *   The log entry that should capture messages.
   */
  public function catchMessages($log_entry) {
    $class = get_class($this);
    if (!isset($class::$log_entries)) {
      $class::$log_entries = array();

      // Since we may already be inside a drupal_register_shutdown_function()
      // we cannot use that. Use PHPs register_shutdown_function() instead.
      ultimate_cron_register_shutdown_function(array(
        $class,
        'catchMessagesShutdownWrapper',
      ), $class);
    }
    $class::$log_entries[$log_entry->lid] = $log_entry;
  }

  /**
   * End message capturing.
   *
   * Effectively disables the shutdown function for the given log entry.
   *
   * @param UltimateCronLogEntry $log_entry
   *   The log entry.
   */
  public function unCatchMessages($log_entry) {
    $class = get_class($this);
    unset($class::$log_entries[$log_entry->lid]);
  }

  /**
   * Invoke loggers watchdog hooks.
   *
   * @param array $log_entry
   *   Watchdog log entry array.
   */
  public static final function hook_watchdog(array $log_entry) {
    if (self::$log_entries) {
      foreach (self::$log_entries as $log_entry_object) {
        $log_entry_object
          ->watchdog($log_entry);
      }
    }
  }

  /**
   * Log to ultimate cron logs only.
   *
   * @see watchdog()
   */
  public static final function log($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
    if (self::$log_entries) {
      foreach (self::$log_entries as $log_entry_object) {
        $log_entry_object
          ->log($type, $message, $variables, $severity, $link);
      }
    }
  }

  /**
   * Shutdown handler wrapper for catching messages.
   *
   * @param string $class
   *   The class in question.
   */
  public static function catchMessagesShutdownWrapper($class) {
    if ($class::$log_entries) {
      foreach ($class::$log_entries as $log_entry) {
        $log_entry->logger
          ->catchMessagesShutdown($log_entry);
      }
    }
  }

  /**
   * PHP shutdown function callback.
   *
   * Ensures that a log entry has been closed properly on shutdown.
   *
   * @param UltimateCronLogEntry $log_entry
   *   The log entry to close.
   */
  public function catchMessagesShutdown($log_entry) {
    $this
      ->unCatchMessages($log_entry);
    if ($log_entry->finished) {
      return;
    }

    // Get error messages.
    $error = error_get_last();
    if ($error) {
      $message = $error['message'] . ' (line ' . $error['line'] . ' of ' . $error['file'] . ').' . "\n";
      $severity = WATCHDOG_INFO;
      if ($error['type'] && (E_NOTICE || E_USER_NOTICE || E_USER_WARNING)) {
        $severity = WATCHDOG_NOTICE;
      }
      if ($error['type'] && (E_WARNING || E_CORE_WARNING || E_USER_WARNING)) {
        $severity = WATCHDOG_WARNING;
      }
      if ($error['type'] && (E_ERROR || E_CORE_ERROR || E_USER_ERROR || E_RECOVERABLE_ERROR)) {
        $severity = WATCHDOG_ERROR;
      }
      $log_entry
        ->log($log_entry->name, $message, array(), $severity);
    }
    $log_entry
      ->finish();
  }

  /**
   * Load latest log entry for multiple jobs.
   *
   * This is the fallback method. Loggers should implement an optimized
   * version if possible.
   */
  public function loadLatestLogEntries($jobs, $log_types) {
    $logs = array();
    foreach ($jobs as $job) {
      $logs[$job->name] = $job
        ->loadLatestLogEntry($log_types);
    }
    return $logs;
  }

  /**
   * Load a log.
   *
   * @param string $name
   *   Name of log.
   * @param string $lock_id
   *   Specific lock id.
   *
   * @return UltimateCronLogEntry
   *   Log entry
   */
  public abstract function load($name, $lock_id = NULL, $log_types = array(
    ULTIMATE_CRON_LOG_TYPE_NORMAL,
  ));

  /**
   * Get page with log entries for a job.
   *
   * @param string $name
   *   Name of job.
   * @param array $log_types
   *   Log types to get.
   * @param int $limit
   *   (optional) Number of log entries per page.
   *
   * @return array
   *   Log entries.
   */
  public abstract function getLogEntries($name, $log_types, $limit = 10);

}

Members

Namesort descending Modifiers Type Description Overrides
UltimateCronLogger::$log_entries public static property
UltimateCronLogger::$log_entry_class public property 2
UltimateCronLogger::catchMessages public function Begin capturing messages.
UltimateCronLogger::catchMessagesShutdown public function PHP shutdown function callback.
UltimateCronLogger::catchMessagesShutdownWrapper public static function Shutdown handler wrapper for catching messages.
UltimateCronLogger::create public function Create a new log entry.
UltimateCronLogger::factoryLogEntry public function Factory method for creating a new unsaved log entry object.
UltimateCronLogger::getLogEntries abstract public function Get page with log entries for a job. 2
UltimateCronLogger::hook_watchdog final public static function Invoke loggers watchdog hooks.
UltimateCronLogger::load abstract public function Load a log. 2
UltimateCronLogger::loadLatestLogEntries public function Load latest log entry for multiple jobs. 1
UltimateCronLogger::log final public static function Log to ultimate cron logs only.
UltimateCronLogger::unCatchMessages public function End message capturing.
UltimateCronPlugin::$description public property
UltimateCronPlugin::$globalOptions public static property
UltimateCronPlugin::$instances public static property
UltimateCronPlugin::$multiple public static property 1
UltimateCronPlugin::$name public property
UltimateCronPlugin::$plugin public property
UltimateCronPlugin::$settings public property
UltimateCronPlugin::$title public property
UltimateCronPlugin::$weight public property 1
UltimateCronPlugin::build_operations_alter public function Allow plugins to alter the allowed operations for a job. 2
UltimateCronPlugin::cleanForm public function Clean form of empty fallback values.
UltimateCronPlugin::cronapi public function A hook_cronapi() for plugins. 1
UltimateCronPlugin::cron_alter public function A hook_cron_alter() for plugins. 3
UltimateCronPlugin::cron_post_invoke public function A hook_cron_post_invoke() for plugins.
UltimateCronPlugin::cron_post_launch public function A hook_cron_post_launch() for plugins.
UltimateCronPlugin::cron_post_run public function A hook_cron_post_run() for plugins.
UltimateCronPlugin::cron_post_schedule public function A hook_cron_post_schedule() for plugins. 1
UltimateCronPlugin::cron_pre_invoke public function A hook_cron_pre_invoke() for plugins.
UltimateCronPlugin::cron_pre_launch public function A hook_cron_pre_launch() for plugins.
UltimateCronPlugin::cron_pre_run public function A hook_cron_pre_run() for plugins.
UltimateCronPlugin::cron_pre_schedule public function A hook_cron_pre_schedule() for plugins. 2
UltimateCronPlugin::defaultSettings public function Default settings. 7
UltimateCronPlugin::defaultSettingsForm public static function Default settings form. 1
UltimateCronPlugin::drupal_array_remove_nested_value public function Modified version drupal_array_get_nested_value().
UltimateCronPlugin::factory public static function Singleton factoryLogEntry.
UltimateCronPlugin::fallbackalize public function Process fallback form parameters.
UltimateCronPlugin::formatLabel public function Format label for the plugin. 1
UltimateCronPlugin::formatLabelVerbose public function Format verbose label for the plugin. 1
UltimateCronPlugin::getDefaultSettings public function Get default settings. 1
UltimateCronPlugin::getGlobalOption public static function Get global plugin option.
UltimateCronPlugin::getGlobalOptions public static function Get all global plugin options.
UltimateCronPlugin::hook_cron_alter final public static function Invoke hook_cron_alter() on plugins.
UltimateCronPlugin::hook_cron_post_invoke final public static function Invoke hook_cron_post_invoke() on plugins.
UltimateCronPlugin::hook_cron_post_launch final public static function Invoke hook_cron_post_launch() on plugins.
UltimateCronPlugin::hook_cron_post_run final public static function Invoke hook_cron_post_run() on plugins.
UltimateCronPlugin::hook_cron_post_schedule final public static function Invoke hook_cron_post_schedule() on plugins.
UltimateCronPlugin::hook_cron_pre_invoke final public static function Invoke hook_cron_pre_invoke() on plugins.
UltimateCronPlugin::hook_cron_pre_launch final public static function Invoke hook_cron_pre_launch() on plugins.
UltimateCronPlugin::hook_cron_pre_run final public static function Invoke hook_cron_pre_run() on plugins.
UltimateCronPlugin::hook_cron_pre_schedule final public static function Invoke hook_cron_pre_schedule() on plugins.
UltimateCronPlugin::isValid public function Default plugin valid for all jobs. 2
UltimateCronPlugin::jobSettingsForm public static function Job settings form. 1
UltimateCronPlugin::jobSettingsFormSubmit public static function Job settings form submit handler. 1
UltimateCronPlugin::jobSettingsFormValidate public static function Job settings form validate handler. 1
UltimateCronPlugin::setGlobalOption public static function Set global plugin option.
UltimateCronPlugin::setSettings public function Save settings to db.
UltimateCronPlugin::settingsForm public function Settings form. 8
UltimateCronPlugin::settingsFormSubmit public function Settings form submit handler. 3
UltimateCronPlugin::settingsFormValidate public function Settings form validate handler. 1
UltimateCronPlugin::settingsLabel public function Get label for a specific setting. 3
UltimateCronPlugin::signal public function Signal page for plugins. 2
UltimateCronPlugin::unsetGlobalOption public static function Remove a global plugin option.
UltimateCronPlugin::unsetGlobalOptions public static function Remove all global plugin options.
UltimateCronPlugin::__construct public function Constructor. 1