Part of the LOG ecosystem · 11 projects
This module automatically masks personal data in Drupal log entries before they are saved. It masks email addresses by default and can be extended to mask other data like IP addresses and phone numbers, ensuring sensitive information is protected without altering your code.
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 ([email protected] 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_uriandreferer. - 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 78is 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]__maskedfield 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.
Recommended modules/libraries
- giggsey/libphonenumber-for-php, required by the Log Masker Phone submodule (
composer require giggsey/libphonenumber-for-php).
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_uriandreferer; it does not mask data by itself. - Privacy Log: also privacy-oriented logging.
Ask your assistant about Log Masker
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the LOG ecosystem
Most installed first
Activity
Release Timeline
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 1.0.0-alpha6 | Pre-release | 11 | PHP 8.3 | Nov 1, 2026 | |
| 1.0.0-alpha5 | Pre-release | 10–11 | PHP 8.2 | Oct 12, 2026 | |
| 1.0.0-alpha4 | Pre-release | 10–11 | PHP 8.2 | Oct 8, 2026 | |
| 1.0.0-alpha3 | Pre-release | 10–11 | PHP 8.2 | Oct 8, 2026 | |
| 1.0.0-alpha2 | Pre-release | 10–11 | PHP 8.2 | Oct 7, 2026 | |
| 1.0.0-alpha1 | Pre-release | 10–11 | PHP 8.3 | Oct 7, 2026 |