aubes/shadow-logger-bundle
Symfony bundle adding a Monolog processor to transform/anonymize sensitive log data for GDPR compliance. Supports IP anonymization, hashing, encryption, and field removal via configurable mappings for context/extra, with strict and debug modes.
monolog/monolog package), requiring minimal architectural changes. Laravel’s logging system already supports processors, making this a drop-in solution for GDPR-compliant log anonymization.symfony/dependency-injection) ensure compatibility without tight coupling.ip, hash, encrypt) are decoupled, allowing selective adoption (e.g., use ip for GDPR compliance without encrypt for performance).shadow-logger.yaml), aligning with Laravel’s config/ structure.single, daily, or syslog handlers)..env for secrets (e.g., SHADOW_LOGGER_ENCODER_SALT), reducing configuration drift.AppServiceProvider).single handler for production logs, exclude debug handler).| Risk Area | Severity | Mitigation |
|---|---|---|
| Key Management | High | Requires secure .env storage and rotation. Use Laravel’s Vault or AWS KMS. |
| Performance Overhead | Medium | Encryption/hashing adds CPU cost. Benchmark with ab or Blackfire; cache keys. |
| Transformer Failures | Low | Configurable strict: true/false controls fallback behavior (null vs. original). |
| Nested Field Access | Low | Dot notation uses Symfony\Component\PropertyAccess, which may be slower. |
| Monolog Version Mismatch | Low | Bundle supports Monolog 2/3; Laravel 10+ uses Monolog 3 by default. |
| Custom Transformer Errors | Medium | Undocumented exceptions may crash log processing. Wrap in try-catch in config. |
debug handler)?SHADOW_LOGGER_ENCODER_SALT or encryption keys without breaking historical logs?DefaultEncryptor or a custom solution (e.g., AWS KMS)?ip transformer)?debug: '%kernel.debug%' in production for critical issues?Bundle with a Laravel ServiceProvider (if needed) to publish config and bind services.config() helper to access shadow_logger settings (e.g., config('shadow_logger.mapping'))..env for secrets (e.g., SHADOW_LOGGER_ENCRYPTOR_KEY).Monolog setup (via Illuminate\Log\LogServiceProvider) is compatible. No additional packages required.config/logging.php:
'channels' => [
'single' => [
'processors' => [
Aubes\ShadowLoggerBundle\Processor\ShadowProcessor::class,
],
],
],
ShadowProcessor in AppServiceProvider:
use Aubes\ShadowLoggerBundle\Processor\ShadowProcessor;
use Monolog\Logger;
public function register()
{
$this->app->extend(Logger::class, function ($logger) {
$logger->pushProcessor(new ShadowProcessor(
config('shadow_logger.mapping'),
config('shadow_logger.encoder'),
config('shadow_logger.encryptor')
));
return $logger;
});
}
Log::channel(), Log::error() calls) to identify PII fields.hash for user IDs, ip for IPs, encrypt for emails).php artisan vendor:publish --provider="Aubes\ShadowLoggerBundle\ShadowLoggerBundle"
shadow-logger.yaml with your mapping (start with strict: false for testing).--obfuscated-- or hashed values).Log::info() in a loop).debug: true to catch transformer errors.monolog.processor.error).debug handler).strict mode based on error rates.| Component | Compatibility | Notes |
|---|---|---|
| Laravel Version | 8.0+ (Symfony 5.4+) or 9.0+ (Symfony 6+) | Tested with Symfony 6/7/8; Laravel 10+ uses Monolog 3. |
| Monolog | 2.x or 3.x | Laravel 10+ uses Monolog 3 by default. |
| PHP | 8.1+ | Laravel 9+ requires PHP 8.1+. |
| Database | None (log-only) | No schema changes required. |
| Queue Workers | Yes | Loggers in queue jobs (e.g., Log::error() in HandleJob) are affected. |
| Third-Party Loggers | Partial | Custom Monolog handlers (e.g., Sentry, Papertrail) will process logs. |
ip, hash, and remove transformers for critical PII (e.g., user_ip, email, credit_card).encrypt transformer for reversible anonymization (e.g., support GDPR right of access).truncate for tokens).tideways/xhprof-laravel and optimize transformer scoping..env updates).shadow-logger.yaml may diverge across environments.config() caching or environment variables for dynamic values (e.g., salt).composer.json until stability is confirmed.How can I help you explore Laravel packages today?