LogRetention
in package
FinalYes
Retention of the `log/` directory: deletes old Tracy dumps and rotates oversized logs.
Without it the directory grows without bound, because nothing else cleans logs.
Both operations touch only the root of the given directory (subdirectories such as saved/
are left alone):
- Tracy dumps
<channel>--YYYY-MM-DD--HH-MM--<hash>.html|.mdolder than N days are deleted. - A
*.logover the size limit is renamed to.log.1, older generations shift to.2,.3and the oldest is dropped. Tracy opens the file on every write, so the next line simply creates a new*.log; nothing is lost or locked.
Run by the cron LogPresenter.
Table of Contents
Constants
- DEFAULT_DAYS : int = 30
- DEFAULT_MAX_SIZE_MB : int = 50
- GENERATIONS : int = 3
- Number of rotated generations (`.1` to `.N`) kept next to the live file.
- DUMP_PATTERN : string = '#^[\w.-]+--\d{4}-\d{2}-\d{2}--\d{2}-\d{2}--[0-...
- Dump file name as written by `Tracy\Logger::getExceptionFile()`.
Methods
-
purge()
: array{dumps_deleted: int, dumps_bytes: int, logs_rotated: list
} - rotate() : bool
- Renames `x.log` to `x.log.1`, shifts older generations by one and drops the oldest (`.GENERATIONS`).
Constants
DEFAULT_DAYS
public
int
DEFAULT_DAYS
= 30
DEFAULT_MAX_SIZE_MB
public
int
DEFAULT_MAX_SIZE_MB
= 50
GENERATIONS
Number of rotated generations (`.1` to `.N`) kept next to the live file.
public
int
GENERATIONS
= 3
DUMP_PATTERN
Dump file name as written by `Tracy\Logger::getExceptionFile()`.
private
string
DUMP_PATTERN
= '#^[\w.-]+--\d{4}-\d{2}-\d{2}--\d{2}-\d{2}--[0-9a-f]+\.(html|md)$#D'
Methods
purge()
public
purge(string $logDir[, int $days = self::DEFAULT_DAYS ][, int $maxSizeMb = self::DEFAULT_MAX_SIZE_MB ][, int|null $now = null ]) : array{dumps_deleted: int, dumps_bytes: int, logs_rotated: list}
Parameters
- $logDir : string
- $days : int = self::DEFAULT_DAYS
- $maxSizeMb : int = self::DEFAULT_MAX_SIZE_MB
- $now : int|null = null
Return values
array{dumps_deleted: int, dumps_bytes: int, logs_rotated: listrotate()
Renames `x.log` to `x.log.1`, shifts older generations by one and drops the oldest (`.GENERATIONS`).
private
rotate(string $file) : bool
Parameters
- $file : string