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.

Saving to a 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
  • $name must be a lowercase word using only [-._a-z0-9] characters, no extension.
  • Passing an array or object for $text saves 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:

OptionDescription
showUserInclude username in the entry? (default=true)
showURLInclude current URL in the entry? (default=true)
userUser, username string, or null to use current user (default=null)
urlURL to record; default is auto-detected from current request
maxLineLengthMax bytes per log line (default=8192)
allowNewlinesPreserve newlines in text? (default=false)
queueQueue 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 true for $flags to 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");
Reading a log

$log->getEntries($name, $options)

Get log entries as structured associative arrays. Most useful for programmatic access.

  • Arguments: getEntries(string $name, array $options = [])
  • Returns: array of associative arrays, each with keys:
    • date (string) — formatted date/time
    • user (string|false) — username, or false if unknown
    • url (string|false) — URL, or false if unknown
    • text (string) — log message
  • Pagination aware (reads $input->pageNum automatically).
$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:

OptionDescription
limitMax entries to return (default=100)
textFilter to entries containing this string
dateFromOldest date to include (unix timestamp or date string)
dateToNewest date to include (unix timestamp or date string, default=now)
reverseReverse order, newest first? (default=true)
pageNumPagination 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');
Inspecting logs

$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 extension
    • file (string) — full path to log file
    • size (int) — file size in bytes
    • modified (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
Managing logs

$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 true to throw WireException if any deletion fails.
$deleted = $log->deleteAll();
Built-in logs

ProcessWire writes to several logs automatically. These are viewable in the admin at Setup > Logs:

Log nameDescription
errorsPHP errors and exceptions caught by ProcessWire
exceptionsUnhandled exceptions (enabled via $config->logs)
messagesEntries written via $log->message()
modulesModule install/uninstall/upgrade activity (enabled via $config->logs)
warningsEntries 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']);
Notes
  • Source file: wire/core/Log/WireLog.php (backed by 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 queue option on save() 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(), and error() double as both logging and ProcessWire notice methods — passing true as $flags displays the message interactively in the admin.
  • save() is hookable (___save()), making it straightforward to intercept or redirect log entries to an external logging system.
API reference: methods, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireLog class also inherits all the methods and properties of: Wire.

Show $var?     Show args?       Only hookable?    

Common

NameReturnSummary 
$log->deleteAll()
array

Delete all log files

 
$log->disable(string $name)
self

Disable the given log name temporarily so that save() calls do not record entries during this request

 
$log->enable(string $name)
self

Enable a previously disabled log

 
$log->error($text)
Wire WireLog

Record an error message in the error log (errors.txt)

 
$log->exists(string $name)
bool

Does given log name exist?

 
$log->message($text)
Wire WireLog

Record an informational or 'success' message in the message log (messages.txt)

 
$log->path()
string

Return disk path to log files

 
$log->pruneAll(int $days)
array

Prune all log files to given number of days

 
$log->save(string $name, $text)
bool

Save text to a named log

$log->warning($text)
Wire WireLog

Record a warning message in the warnings log (warnings.txt)

 

Retrieval

NameReturnSummary 
$log->getEntries(string $name)
array

Return given number of entries from end of log file, with each entry as an associative array of components

 
$log->getFilename(string $name)
string

Get the full filename (including path) for the given log name

 
$log->getLines(string $name)
array

Return the given number of entries from the end of log file

 
$log->getLogs()
array

Return array of all logs, sorted by name

 
$log->getTotalEntries(string $name)
int

Get the total number of entries present in the given log

 

Manipulation

NameReturnSummary 
$log->delete(string $name)
bool

Delete a log file

 
$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, WireLog also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.261