Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
wp-content
/
plugins
/
gplvault-updater
/
includes
/
logger
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php defined('ABSPATH') || exit; class GPLVault_Logger implements GPLVault_Logger_Interface { protected $handlers; protected $threshold; public function __construct($handlers = null, $threshold = null) { if (null === $handlers) { $handlers = apply_filters('gplvault_register_log_handlers', array()); } $register_handlers = array(); if (!empty($handlers) && is_array($handlers)) { foreach ($handlers as $handler) { $implements = class_implements($handler); if (is_object($handler) && is_array($implements) && in_array('GPLVault_Log_Handler_Interface', $implements, true)) { $register_handlers[] = $handler; } else { gv_doing_it_wrong(__METHOD__, sprintf(__('The provided handler %1$s does not implement %2$s.', 'gplvault'), '<code>' . esc_html(is_object($handler) ? get_class($handler) : $handler) . '</code>', '<code>GPLVault_Log_Handler_Interface</code>'), '2.1.0'); } } } if (null !== $threshold) { $threshold = GPLVault_Log_Levels::get_level_severity($threshold); } elseif (defined('GV_UPDATER_LOG_THRESHOLD') && GPLVault_Log_Levels::is_valid_level(GV_UPDATER_LOG_THRESHOLD)) { $threshold = GPLVault_Log_Levels::get_level_severity(GV_UPDATER_LOG_THRESHOLD); } else { $threshold = null; } $this->handlers = $register_handlers; $this->threshold = $threshold; } protected function should_handle($level) { if (null === $this->threshold) { return true; } return $this->threshold <= GPLVault_Log_Levels::get_level_severity($level); } public function add($handle, $message, $level = GPLVault_Log_Levels::NOTICE) { $message = apply_filters('gplvault_logger_add_message', $message, $handle); $this->log($level, $message, array('source' => $handle, '_legacy' => true)); return true; } public function log($level, $message, $context = array()) { if (!GPLVault_Log_Levels::is_valid_level($level)) { gv_doing_it_wrong(__METHOD__, sprintf(__('%1$s was called with an invalid level "%2$s".', 'gplvault'), '<code>GPLVault_Logger::log</code>', $level), '2.1.0'); } if ($this->should_handle($level)) { $timestamp = time(); $message = apply_filters('gplvault_logger_log_message', $message, $level, $context); foreach ($this->handlers as $handler) { $handler->handle($timestamp, $level, $message, $context); } } } public function emergency($message, $context = array()) { $this->log(GPLVault_Log_Levels::EMERGENCY, $message, $context); } public function alert($message, $context = array()) { $this->log(GPLVault_Log_Levels::ALERT, $message, $context); } public function critical($message, $context = array()) { $this->log(GPLVault_Log_Levels::CRITICAL, $message, $context); } public function error($message, $context = array()) { $this->log(GPLVault_Log_Levels::ERROR, $message, $context); } public function warning($message, $context = array()) { $this->log(GPLVault_Log_Levels::WARNING, $message, $context); } public function notice($message, $context = array()) { $this->log(GPLVault_Log_Levels::NOTICE, $message, $context); } public function info($message, $context = array()) { $this->log(GPLVault_Log_Levels::INFO, $message, $context); } public function debug($message, $context = array()) { $this->log(GPLVault_Log_Levels::DEBUG, $message, $context); } public function clear($source = '') { if (!$source) { return false; } foreach ($this->handlers as $handler) { if (is_callable(array($handler, 'clear'))) { $handler->clear($source); } } return true; } public function clear_expired_logs() { $days = absint(apply_filters('gplvault_logger_days_to_retain_logs', 30)); $timestamp = strtotime("-{$days} days"); foreach ($this->handlers as $handler) { if (is_callable(array($handler, 'delete_logs_before_timestamp'))) { $handler->delete_logs_before_timestamp($timestamp); } } } }