This project is not covered by Drupal’s security advisory policy.

Log Masker masks personal data in every Drupal log entry before it reaches a logger, without changing the calling code. Its goal is to mask as much personal data as possible: each kind of data is handled by a masking rule. The core module ships the rule for email addresses (jean.dupont@example.com is logged as j***.***@e***.***). Two optional submodules add phone numbers and the values of declared entity fields such as names. Rules for IP addresses are planned, and sites can add their own rules.

Features

  • Works with every logger (dblog, syslog, contrib loggers) and every channel, including \Drupal::logger().
  • Masks the message, the placeholders, nested context values, request_uri and referer.
  • Detects URL-encoded addresses (jean.dupont%40example.com), addresses in JSON payloads and exception messages (e.g. Guzzle), and addresses truncated at the end of a value.
  • Exceptions in the log context are replaced by a neutral, masked exception.
  • Fail-closed by default: if masking fails, the message is withheld instead of being written unmasked.
  • The logger.* services keep their own class: no decoration, no replacement of the logger factory.
  • Extensible: add your own rules as services tagged log_masker.rule.

Submodules (optional)

  • Log Masker Phone (log_masker_phone): masks phone numbers in any text. International numbers of every country, and national numbers of the site's default country written with separators: +33 6 12 34 56 78 is logged as +33 ***78. Requires the giggsey/libphonenumber-for-php library.
  • Log Masker Fields (log_masker_fields): a name has no recognizable shape, so this module masks what you declare sensitive. Declare an entity field (names, addresses, IBANs...), choose a strategy (initials, fixed marker, partial reveal), and put the field object in the log context instead of its value: Updated J***-P***. The settings of each strategy can be overridden per field. Strategies are plugins, and each declared field also gets a read-only computed [field]__masked field for views, tokens and mail templates.

This is pseudonymisation, not anonymisation (GDPR recital 26). Masked logs remain personal data; not logging the data remains the best protection.

Post-Installation

Masking is active as soon as the module is installed. Settings are under Configuration > Development > Log Masker (permission Administer Log Masker), displayed as tabs: General (mask character and length, revealed characters, failure mode and excluded channels), Phone and Fields when the submodules are enabled. Each page shows a preview or an example on fictitious values and explains each setting. Disabling masking requires an explicit confirmation, every change is audited, and the status report warns about any weakened setting and about loggers that escape masking.

To mask a declared field, add it on the Fields tab, then log the field object, not its value: $logger->info('Updated @name', ['@name' => $user->get('field_first_name')]);. A value passed as a string is not recognized.

Additional Requirements

Drupal core 11.4 or 12 and PHP 8.3 or later. No other dependency, except for the Phone submodule (see below). Sites on Drupal 10 can use 1.0.0-alpha5.

Note: with the Monolog module enabled, version 1 cannot mask (the status report shows an error). Monolog support is planned for 2.x.

Similar projects

  • Log Middleware: a generic hook to alter log entries. It replaces the logger factory and runs before the channel adds request_uri and referer; it does not mask data by itself.
  • Privacy Log: also privacy-oriented logging.

Project information

Releases