first commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Akeeba Engine
|
||||
*
|
||||
* @package akeebaengine
|
||||
* @copyright Copyright (c)2006-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace Akeeba\Engine\Util\Log;
|
||||
|
||||
defined('AKEEBAENGINE') || die();
|
||||
|
||||
/**
|
||||
* The interface for Akeeba Engine logger objects
|
||||
*/
|
||||
interface LogInterface
|
||||
{
|
||||
/**
|
||||
* Open a new log instance with the specified tag. If another log is already open it is closed before switching to
|
||||
* the new log tag. If the tag is null use the default log defined in the logging system.
|
||||
*
|
||||
* @param string|null $tag The log to open
|
||||
* @param string $extension The log file extension (default: .php, use empty string for .log files)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function open($tag = null, $extension = '.php');
|
||||
|
||||
/**
|
||||
* Close the currently active log and set the current tag to null.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function close();
|
||||
|
||||
/**
|
||||
* Reset (remove entries) of the log with the specified tag.
|
||||
*
|
||||
* @param string|null $tag The log to reset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset($tag = null);
|
||||
|
||||
/**
|
||||
* Add a message to the log
|
||||
*
|
||||
* @param string $level One of the Akeeba\Engine\Psr\Log\LogLevel constants
|
||||
* @param string $message The message to log
|
||||
* @param array $context Currently not used. Left here for PSR-3 compatibility.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function log($level, $message, array $context = []);
|
||||
|
||||
/**
|
||||
* Temporarily pause log output. The log() method MUST respect this.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function pause();
|
||||
|
||||
/**
|
||||
* Resume the previously paused log output. The log() method MUST respect this.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unpause();
|
||||
|
||||
/**
|
||||
* Returns the timestamp (in UNIX time long integer format) of the last log message written to the log with the
|
||||
* specific tag. The timestamp MUST be read from the log itself, not from the logger object. It is used by the
|
||||
* engine to find out the age of stalled backups which may have crashed.
|
||||
*
|
||||
* @param string|null $tag The log tag for which the last timestamp is returned
|
||||
*
|
||||
* @return int|null The timestamp of the last log message, in UNIX time. NULL if we can't get the timestamp.
|
||||
*/
|
||||
public function getLastTimestamp($tag = null);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Akeeba Engine
|
||||
*
|
||||
* @package akeebaengine
|
||||
* @copyright Copyright (c)2006-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace Akeeba\Engine\Util\Log;
|
||||
|
||||
defined('AKEEBAENGINE') || die();
|
||||
|
||||
trait WarningsLoggerAware
|
||||
{
|
||||
/**
|
||||
* The warnings in the current queue
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $warningsQueue = [];
|
||||
|
||||
/**
|
||||
* The maximum length of the warnings queue
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $warningsQueueSize = 0;
|
||||
|
||||
/**
|
||||
* A combination of getWarnings() and resetWarnings(). Returns the warnings and immediately resets the warnings
|
||||
* queue.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getAndResetWarnings()
|
||||
{
|
||||
$ret = $this->getWarnings();
|
||||
|
||||
$this->resetWarnings();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all warnings logged since the last time warnings were reset. The maximum number of warnings
|
||||
* returned is controlled by setWarningsQueueSize().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getWarnings()
|
||||
{
|
||||
return $this->warningsQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the warnings queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function resetWarnings()
|
||||
{
|
||||
$this->warningsQueue = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the warnings queue size.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
final public function getWarningsQueueSize()
|
||||
{
|
||||
return $this->warningsQueueSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the warnings queue size. A size of 0 means "no limit".
|
||||
*
|
||||
* @param int $queueSize The size of the warnings queue (in number of warnings items)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function setWarningsQueueSize($queueSize = 0)
|
||||
{
|
||||
if (!is_numeric($queueSize) || empty($queueSize) || ($queueSize < 0))
|
||||
{
|
||||
$queueSize = 0;
|
||||
}
|
||||
|
||||
$this->warningsQueueSize = $queueSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a warning to the warnings queue.
|
||||
*
|
||||
* @param string $warning
|
||||
*/
|
||||
final protected function enqueueWarning($warning)
|
||||
{
|
||||
$this->warningsQueue[] = $warning;
|
||||
|
||||
// If there is no queue size limit there's nothing else to be done.
|
||||
if ($this->warningsQueueSize <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If the queue size is exceeded remove as many of the earliest elements as required
|
||||
if (count($this->warningsQueue) > $this->warningsQueueSize)
|
||||
{
|
||||
$this->warningsQueueSize = array_slice($this->warningsQueue, -$this->warningsQueueSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Akeeba Engine
|
||||
*
|
||||
* @package akeebaengine
|
||||
* @copyright Copyright (c)2006-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace Akeeba\Engine\Util\Log;
|
||||
|
||||
defined('AKEEBAENGINE') || die();
|
||||
|
||||
interface WarningsLoggerInterface
|
||||
{
|
||||
/**
|
||||
* Returns an array with all warnings logged since the last time warnings were reset. The maximum number of warnings
|
||||
* returned is controlled by setWarningsQueueSize().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWarnings();
|
||||
|
||||
/**
|
||||
* Resets the warnings queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetWarnings();
|
||||
|
||||
/**
|
||||
* A combination of getWarnings() and resetWarnings(). Returns the warnings and immediately resets the warnings
|
||||
* queue.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAndResetWarnings();
|
||||
|
||||
/**
|
||||
* Set the warnings queue size. A size of 0 means "no limit".
|
||||
*
|
||||
* @param int $queueSize The size of the warnings queue (in number of warnings items)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setWarningsQueueSize($queueSize = 0);
|
||||
|
||||
/**
|
||||
* Returns the warnings queue size.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWarningsQueueSize();
|
||||
}
|
||||
Reference in New Issue
Block a user