WireLog / $log
$log is the API variable for reading and writing log files in ProcessWire
Logs are
plain-text files stored in /site/assets/logs/ and viewable in the admin at
Setup > Logs. Each entry records a date/time, username, URL, and message.
$log is accessible in templates as $log, wire()->log, or log() (if the
functions API is enabled); and in modules as $this->wire()->log.
$log->save($name, $text, $options)
Save an entry to a named log file. Creates the log if it doesn't exist.
- Arguments:
save(string $name, string|array|object $text, array $options = []) - Returns:
bool $namemust be a lowercase word using only[-._a-z0-9]characters, no extension.- Passing an array or object for
$textsaves it as a JSON entry 3.0.256+. - This is a hookable method (
___save()).
// Log a plain text message to /site/assets/logs/search.txt
$log->save('search', "User searched for: $phrase");
// Log structured data as JSON 3.0.256+
$log->save('orders', ['id' => 123, 'total' => 49.95, 'status' => 'paid']);Key options:
| Option | Description |
|---|---|
showUser | Include username in the entry? (default=true) |
showURL | Include current URL in the entry? (default=true) |
user | User, username string, or null to use current user (default=null) |
url | URL to record; default is auto-detected from current request |
maxLineLength | Max bytes per log line (default=8192) |
allowNewlines | Preserve newlines in text? (default=false) |
queue | Queue entry to save at end of request, grouping same-name entries (default=false) |
$log->message($text)
Save a message to the built-in messages log (messages.txt). Optionally also
displays it as a notice to the admin user.
- Arguments:
message(string $text, bool|int $flags = 0) - Returns:
$this - Pass
truefor$flagsto also display the message interactively in the admin.
$log->message("User {$user->name} updated their profile");$log->warning($text)
Save a warning to the built-in warnings log (warnings.txt).
- Arguments:
warning(string $text, bool|int $flags = 0) - Returns:
$this
$log->warning("Config value 'fooSetting' is deprecated");$log->error($text)
Save an error to the built-in errors log (errors.txt).
- Arguments:
error(string $text, bool|int $flags = 0) - Returns:
$this
$log->error("Failed to connect to payment gateway");$log->getEntries($name, $options)
Get log entries as structured associative arrays. Most useful for programmatic access.
- Arguments:
getEntries(string $name, array $options = []) - Returns:
arrayof associative arrays, each with keys:date(string) — formatted date/timeuser(string|false) — username, orfalseif unknownurl(string|false) — URL, orfalseif unknowntext(string) — log message
- Pagination aware (reads
$input->pageNumautomatically).
$entries = $log->getEntries('search', ['limit' => 50]);
foreach($entries as $entry) {
echo "$entry[date] — $entry[user] — $entry[text]\n";
}
// Filter by date range
$entries = $log->getEntries('errors', [
'dateFrom' => '2025-01-01',
'dateTo' => '2025-01-31',
'limit' => 100,
]);
// Search for text
$entries = $log->getEntries('search', ['text' => 'processwire', 'limit' => 25]);Options:
| Option | Description |
|---|---|
limit | Max entries to return (default=100) |
text | Filter to entries containing this string |
dateFrom | Oldest date to include (unix timestamp or date string) |
dateTo | Newest date to include (unix timestamp or date string, default=now) |
reverse | Reverse order, newest first? (default=true) |
pageNum | Pagination page number (default=auto-detect) |
$log->getLines($name, $options)
Same as getEntries() but returns raw tab-delimited strings rather than structured arrays.
Accepts the same options.
$lines = $log->getLines('search', ['limit' => 20]);
foreach($lines as $line) echo $line . "\n";$log->getTotalEntries($name)
Get the total number of entries in a log.
- Returns:
int
$total = $log->getTotalEntries('errors');$log->getLogs($sortNewest)
Get an array of all available logs.
- Arguments:
getLogs(bool $sortNewest = false) - Returns:
array— indexed by log name, each value is an associative array with:name(string) — log name without extensionfile(string) — full path to log filesize(int) — file size in bytesmodified(int) — last-modified unix timestamp
foreach($log->getLogs() as $name => $info) {
echo "$name: " . number_format($info['size']) . " bytes\n";
}
// Sort by most recently modified
$logs = $log->getLogs(true);$log->exists($name)
Check whether a log exists.
- Returns:
bool
if($log->exists('search')) {
$entries = $log->getEntries('search');
}$log->getFilename($name)
Get the full filesystem path to a log file.
- Returns:
string
$path = $log->getFilename('errors');
// e.g. /var/www/html/site/assets/logs/errors.txt$log->prune($name, $days)
Remove all entries older than $days days from a log.
- Arguments:
prune(string $name, int $days) - Returns:
int— number of entries remaining after pruning
// Keep only the last 30 days of search logs
$log->prune('search', 30);$log->pruneAll($days)
Prune all log files to the given number of days.
- Arguments:
pruneAll(int $days) - Returns:
array— log name => remaining entry count
$log->pruneAll(90);$log->delete($name)
Delete a log file entirely.
- Returns:
bool
$log->delete('search');$log->deleteAll($throw)
Delete all log files.
- Arguments:
deleteAll(bool $throw = false) - Returns:
array— names of deleted logs - Pass
trueto throwWireExceptionif any deletion fails.
$deleted = $log->deleteAll();ProcessWire writes to several logs automatically. These are viewable in the admin at Setup > Logs:
| Log name | Description |
|---|---|
errors | PHP errors and exceptions caught by ProcessWire |
exceptions | Unhandled exceptions (enabled via $config->logs) |
messages | Entries written via $log->message() |
modules | Module install/uninstall/upgrade activity (enabled via $config->logs) |
warnings | Entries written via $log->warning() |
Additional built-in logs (deprecated, 404, etc.) may appear depending on
configuration and installed modules.
Enable or disable built-in logs in /site/config.php:
// Enable the 'deprecated' log (tracks use of deprecated methods)
$config->logs[] = 'deprecated';
// Disable the 'modules' log
$config->logs = array_diff($config->logs, ['modules']);- Source file:
wire/core/Log/Wire(backed byLog.php wire/core/Log/FileLog.php). - Log files are plain text at
/site/assets/logs/[name].txt, one entry per line, tab-delimited:date\tuser\turl\ttext. - The
queueoption onsave()defers writing until the end of the request, grouping multiple entries with the same name/options into one newline-separated line — useful for high-frequency logging without repeated file writes. message(),warning(), anderror()double as both logging and ProcessWire notice methods — passingtrueas$flagsdisplays the message interactively in the admin.save()is hookable (___save()), making it straightforward to intercept or redirect log entries to an external logging system.
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Wire class also inherits all the methods and properties of: Wire.
Common
Retrieval
| Name | Return | Summary | |
|---|---|---|---|
$log->getEntries() $log->getEntries(string $name) $log->getEntries(string $name, array $options = []) | array | Return given number of entries from end of log file, with each entry as an associative array of components | |
$log->getFilename() $log->getFilename(string $name) $log->getFilename(string $name) | string | Get the full filename (including path) for the given log name | |
$log->getLines() $log->getLines(string $name) $log->getLines(string $name, array $options = []) | array | Return the given number of entries from the end of log file | |
$log->getLogs() $log->getLogs() $log->getLogs(bool $sortNewest = false) | array | Return array of all logs, sorted by name | |
$log->getTotalEntries() $log->getTotalEntries(string $name) $log->getTotalEntries(string $name) | int | Get the total number of entries present in the given log |
Manipulation
| Name | Return | Summary | |
|---|---|---|---|
$log->delete() $log->delete(string $name) $log->delete(string $name) | bool | Delete a log file | |
$log->prune() $log->prune(string $name, int $days) $log->prune(string $name, int $days) | int | Prune log file to contain only entries from last [n] days |
Additional methods and properties
In addition to the methods and properties above, Wire
API reference based on ProcessWire core version 3.0.261