class CacheLogger in Ultimate Cron 8.2
Cache Logger.
Plugin annotation
@LoggerPlugin(
id = "cache",
title = @Translation("Cache"),
description = @Translation("Stores the last log entry (and only the last) in the cache."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ultimate_cron\CronPlugin implements ConfigurableInterface, DependentPluginInterface, PluginInspectionInterface, PluginFormInterface
- class \Drupal\ultimate_cron\Logger\LoggerBase implements LoggerInterface
- class \Drupal\ultimate_cron\Plugin\ultimate_cron\Logger\CacheLogger implements ContainerFactoryPluginInterface
- class \Drupal\ultimate_cron\Logger\LoggerBase implements LoggerInterface
- class \Drupal\ultimate_cron\CronPlugin implements ConfigurableInterface, DependentPluginInterface, PluginInspectionInterface, PluginFormInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CacheLogger
1 file declares its use of CacheLogger
- LoggerPluginTest.php in tests/
src/ Kernel/ LoggerPluginTest.php
File
- src/
Plugin/ ultimate_cron/ Logger/ CacheLogger.php, line 22
Namespace
Drupal\ultimate_cron\Plugin\ultimate_cron\LoggerView source
class CacheLogger extends LoggerBase implements ContainerFactoryPluginInterface {
/**
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CacheBackendInterface $cache) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->cache = $cache;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$bin = isset($configuration['bin']) ? $configuration['bin'] : 'ultimate_cron_logger';
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('cache.' . $bin));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'bin' => 'ultimate_cron_logger',
'timeout' => Cache::PERMANENT,
);
}
/**
* {@inheritdoc}
*/
public function load($name, $lock_id = NULL, array $log_types = [
ULTIMATE_CRON_LOG_TYPE_NORMAL,
]) {
$log_entry = new LogEntry($name, $this);
if (!$lock_id) {
$cache = $this->cache
->get('uc-name:' . $name, TRUE);
if (empty($cache) || empty($cache->data)) {
return $log_entry;
}
$lock_id = $cache->data;
}
$cache = $this->cache
->get('uc-lid:' . $lock_id, TRUE);
if (!empty($cache->data)) {
$log_entry
->setData((array) $cache->data);
$log_entry->finished = TRUE;
}
return $log_entry;
}
/**
* {@inheritdoc}
*/
public function getLogEntries($name, array $log_types, $limit = 10) {
$log_entry = $this
->load($name);
return $log_entry->lid ? array(
$log_entry,
) : array();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['bin'] = array(
'#type' => 'textfield',
'#title' => t('Cache bin'),
'#description' => t('Select which cache bin to use for storing logs.'),
'#default_value' => $this->configuration['bin'],
'#fallback' => TRUE,
'#required' => TRUE,
);
$form['timeout'] = array(
'#type' => 'textfield',
'#title' => t('Cache timeout'),
'#description' => t('Seconds before cache entry expires (0 = never, -1 = on next general cache wipe).'),
'#default_value' => $this->configuration['timeout'],
'#fallback' => TRUE,
'#required' => TRUE,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function save(LogEntry $log_entry) {
if (!$log_entry->lid) {
return;
}
$settings = $this
->getConfiguration();
$expire = $settings['timeout'] != Cache::PERMANENT ? REQUEST_TIME + $settings['timeout'] : $settings['timeout'];
$this->cache
->set('uc-name:' . $log_entry->name, $log_entry->lid, $expire);
$this->cache
->set('uc-lid:' . $log_entry->lid, $log_entry
->getData(), $expire);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheLogger:: |
protected | property | ||
CacheLogger:: |
public | function |
Form constructor. Overrides CronPlugin:: |
|
CacheLogger:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
CacheLogger:: |
public | function |
Gets default configuration for this plugin. Overrides CronPlugin:: |
|
CacheLogger:: |
public | function |
Get page with log entries for a job. Overrides LoggerInterface:: |
|
CacheLogger:: |
public | function |
Load a log. Overrides LoggerInterface:: |
|
CacheLogger:: |
public | function |
Saves a log entry. Overrides LoggerInterface:: |
|
CacheLogger:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides CronPlugin:: |
|
CronPlugin:: |
public static | property | ||
CronPlugin:: |
public static | property | ||
CronPlugin:: |
public static | property | 1 | |
CronPlugin:: |
public | property | ||
CronPlugin:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
CronPlugin:: |
public | function | Clean form of empty fallback values. | |
CronPlugin:: |
public | function | Modified version drupal_array_get_nested_value(). | |
CronPlugin:: |
public | function | Process fallback form parameters. | |
CronPlugin:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
CronPlugin:: |
public static | function | Get global plugin option. | |
CronPlugin:: |
public static | function | Get all global plugin options. | |
CronPlugin:: |
public static | function | Returns a list of plugin types. | |
CronPlugin:: |
public | function | Default plugin valid for all jobs. | 1 |
CronPlugin:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
CronPlugin:: |
public static | function | Set global plugin option. | |
CronPlugin:: |
public | function | Get label for a specific setting. | 1 |
CronPlugin:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
CronPlugin:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
LoggerBase:: |
public static | property | ||
LoggerBase:: |
public | function |
Create a new log entry. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Factory method for creating a new unsaved log entry object. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Load latest log entry for multiple jobs. Overrides LoggerInterface:: |
1 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |