Custom Logs

Write to and view log files that have custom column labels and column count.

When you use the core $log->save() method you can only save a single string of text. When you view the log in the core ProcessLogger the columns and their header labels are predetermined.

The Custom Logs module is different in that it lets you write and view log files with the number of columns and the column header labels you specify in the module configuration.

Configuration


In the "Custom logs" textarea field, enter custom logs, one per line, in the format...

name: column label, column label, column label

...with as many comma-separated column labels as needed.

The log name must be a word consisting of only [-._a-z0-9] and no extension.

If you prefix a URL column label with {url} then the value in the column will be rendered as a link in the log viewer.

The date/time will automatically be added as the first column so you do not need to specify it here.

Writing to a custom log


Use the CustomLogs::save($name, $data, $options) method to save data to a custom log file.

$cl = $modules->get('CustomLogs');
$cl->save('my-log', $my_data);

Arguments

$name Name of log to save to (word consisting of only [-._a-z0-9] and no extension).

$data An array of strings to save to the log. The number and order of items in the array should match the columns that are configured for the log.

$options (optional) Options for FileLog::save(). Normally you won't need to use this argument.

Example of use


Custom log definition in the module configuration:

visits: {url}URL, IP Address, User Agent, {url}Referrer

Saving data to the log:

$cl = $modules->get('CustomLogs');
$data = [
    $_SERVER['REQUEST_URI'] ?? '',
    $_SERVER['REMOTE_ADDR'] ?? '',
    $_SERVER['HTTP_USER_AGENT'] ?? '',
    $_SERVER['HTTP_REFERER'] ?? '',
];
$cl->save('visits', $data);

Viewing the resulting log in Setup > Logs > visits:

custom-logs-1

More modules by Robin S

  • Hanna Code Dialog

    Enhances the use of Hanna tags in CKEditor fields, including the dialog-based editing of Hanna tags.
  • Connect Page Fields

    Allows the connecting of two related Page fields so that changing one updates the other.
  • Minimal Fieldset

    Adds a config option to fieldsets to render them without label or padding in Page Edit.
  • Template Field Widths

    Quickly set the widths of inputfields in a template.
  • Custom Inputfield Dependencies

    Extends inputfield dependencies so that inputfield visibility or required status may be determined at runtime by selector or custom PHP code.
  • Breadcrumb Dropdowns

    Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.
  • Auto Template Stubs

    Automatically creates stub files for templates when fields or fieldgroups are saved.
  • Custom Admin Menus

    Adds up to three custom dropdowns to the main admin menu.
  • Page List Select Multiple Quickly

    Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing.

All modules by Robin S

Install and use modules at your own risk. Always have a site and database backup before installing new modules.