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
- class \UltimateCronPlugin
- class \UltimateCronLogger
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UltimateCronLogger:: |
public static | property | ||
UltimateCronLogger:: |
public | property | 2 | |
UltimateCronLogger:: |
public | function | Begin capturing messages. | |
UltimateCronLogger:: |
public | function | PHP shutdown function callback. | |
UltimateCronLogger:: |
public static | function | Shutdown handler wrapper for catching messages. | |
UltimateCronLogger:: |
public | function | Create a new log entry. | |
UltimateCronLogger:: |
public | function | Factory method for creating a new unsaved log entry object. | |
UltimateCronLogger:: |
abstract public | function | Get page with log entries for a job. | 2 |
UltimateCronLogger:: |
final public static | function | Invoke loggers watchdog hooks. | |
UltimateCronLogger:: |
abstract public | function | Load a log. | 2 |
UltimateCronLogger:: |
public | function | Load latest log entry for multiple jobs. | 1 |
UltimateCronLogger:: |
final public static | function | Log to ultimate cron logs only. | |
UltimateCronLogger:: |
public | function | End message capturing. | |
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public static | property | ||
UltimateCronPlugin:: |
public static | property | ||
UltimateCronPlugin:: |
public static | property | 1 | |
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | 1 | |
UltimateCronPlugin:: |
public | function | Allow plugins to alter the allowed operations for a job. | 2 |
UltimateCronPlugin:: |
public | function | Clean form of empty fallback values. | |
UltimateCronPlugin:: |
public | function | A hook_cronapi() for plugins. | 1 |
UltimateCronPlugin:: |
public | function | A hook_cron_alter() for plugins. | 3 |
UltimateCronPlugin:: |
public | function | A hook_cron_post_invoke() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_post_launch() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_post_run() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_post_schedule() for plugins. | 1 |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_invoke() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_launch() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_run() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_schedule() for plugins. | 2 |
UltimateCronPlugin:: |
public | function | Default settings. | 7 |
UltimateCronPlugin:: |
public static | function | Default settings form. | 1 |
UltimateCronPlugin:: |
public | function | Modified version drupal_array_get_nested_value(). | |
UltimateCronPlugin:: |
public static | function | Singleton factoryLogEntry. | |
UltimateCronPlugin:: |
public | function | Process fallback form parameters. | |
UltimateCronPlugin:: |
public | function | Format label for the plugin. | 1 |
UltimateCronPlugin:: |
public | function | Format verbose label for the plugin. | 1 |
UltimateCronPlugin:: |
public | function | Get default settings. | 1 |
UltimateCronPlugin:: |
public static | function | Get global plugin option. | |
UltimateCronPlugin:: |
public static | function | Get all global plugin options. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_alter() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_invoke() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_launch() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_run() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_schedule() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_invoke() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_launch() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_run() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_schedule() on plugins. | |
UltimateCronPlugin:: |
public | function | Default plugin valid for all jobs. | 2 |
UltimateCronPlugin:: |
public static | function | Job settings form. | 1 |
UltimateCronPlugin:: |
public static | function | Job settings form submit handler. | 1 |
UltimateCronPlugin:: |
public static | function | Job settings form validate handler. | 1 |
UltimateCronPlugin:: |
public static | function | Set global plugin option. | |
UltimateCronPlugin:: |
public | function | Save settings to db. | |
UltimateCronPlugin:: |
public | function | Settings form. | 8 |
UltimateCronPlugin:: |
public | function | Settings form submit handler. | 3 |
UltimateCronPlugin:: |
public | function | Settings form validate handler. | 1 |
UltimateCronPlugin:: |
public | function | Get label for a specific setting. | 3 |
UltimateCronPlugin:: |
public | function | Signal page for plugins. | 2 |
UltimateCronPlugin:: |
public static | function | Remove a global plugin option. | |
UltimateCronPlugin:: |
public static | function | Remove all global plugin options. | |
UltimateCronPlugin:: |
public | function | Constructor. | 1 |