Intelligent Log Sanitization for Java β Automatically detect and mask sensitive data in logs using rule-based analysis and AI.
LogGuardAI is a Log4j2 plugin that intercepts log events and intelligently sanitizes them to prevent accidental exposure of sensitive data like passwords, API keys, tokens, and personal information. It also supports logs-to-metrics extraction for Log4j2, converting log lines into Prometheus-style metrics using custom regex patterns.
β Logs with secrets:
[LOG] User auth: userId=12345 apiKey=sk-abcdef123456 password=secret
β Oops! Now this secret is in logs, monitoring dashboards, and backups!
β
Logs with LogGuardAI:
[LOG] User auth: userId=***** apiKey=***** password=*****
β Secrets automatically masked, structure preserved!
-
π 20+ Sensitive Keyword Detectionβ Automatically detects passwords, tokens, API keys, etc. - π Smart Risk Scoringβ Multi-factor analysis (keywords, patterns, entropy) - β‘ Lightning Fastβ <5ms latency, non-blocking design - π‘οΈ Fail-Safeβ Logging never breaks, even if something fails - π Structured Data Supportβ Handles key=value, JSON, query strings
-
π§ AI-Powered Sanitizationβ OpenAI GPT-based intelligent masking with context - π° LRU Cachingβ 80-95% cache hit rate =** 80% cost savings** - π Enhanced Exceptionsβ AI explains what went wrong - π Data Classificationβ Automatically identify PII vs. sensitive data - π Configurable Samplingβ Control AI costs (5%-100%)
π¦
Batch AI Processingβ Process multiple sensitive values together (5x efficiency) - β‘
Async/Non-Blockingβ AI calls never block log threads (<5ms guaranteed) - π
Smart Fallbacksβ Rule-based masking if AI fails or times out - π
Spring Boot Compatibilityβ Fixed Log4j2 plugin registration issues
- π€ Multi-Provider AIβ OpenAI, Anthropic Claude, or Azure OpenAI - ποΈ Anthropic Claude Integrationβ Claude 3 models with Messages API - βοΈ Azure OpenAI Integrationβ Custom endpoints and deployments - π§ Provider-Specific Configurationβ Azure endpoints, deployments, API versions - π·οΈ Enhanced Model Supportβ GPT-4, Claude 3, Azure deployments - π Configurable Batch Sizeβ Tune performance vs. API efficiency - π€ Multi-Provider Supportβ OpenAI, Anthropic Claude, Azure OpenAI - π Metrics Extractionβ Convert legacy unstructured logs into rich JSON metrics. - ποΈ Backward Compatibleβ Existing configurations work unchanged
Released: May 27, 2026
- π Pattern-Based Metricsβ Define custom regex patterns to extract metrics directly from logs - π― User-Defined Patternsβ Create metrics for HTTP requests, FTP transfers, database queries, etc. - πΎ Append-Only Fileβ Metrics stored in Prometheus text format with cumulative history - π Logs-to-Metrics Conversionβ Convert Log4j2 log entries into counters and labels for monitoring and alerting - βοΈ Periodic Flushingβ Configurable flush interval (default: 60 seconds) - π Cardinality Protectionβ Configurable limits prevent unbounded metric combinations (default: 10,000) - π Zero Dependenciesβ No external monitoring infrastructure required
<LogGuardLayout
extractMetrics="true"
metricsFilePath="logs/metrics.txt"
metricsFlushIntervalMs="60000"
metricsMaxCardinality="10000"
metricsPatterns="http_requests|(GET|POST|DELETE) ([/\\w/]+) (\\d{3})|http_requests_total|method,endpoint,status"/>
See Metrics Configuration for full configuration details and examples.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.logguardai</groupId>
<artifactId>logguardai</artifactId>
<version>0.5.0</version> <!-- Latest: Logs to metrics -->
</dependency>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<LogGuardLayout/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Tip: To enable pattern-based metrics, set extractMetrics="true"
and configure metricsFilePath
, metricsFlushIntervalMs
, metricsMaxCardinality
, and metricsPatterns
as shown in the v0.5 section above.
LogGuardAI v0.5 makes it easy to transform Log4j2 log messages into Prometheus-compatible metrics. Use metricsPatterns
to extract method, endpoint, status, latency, and other useful labels from structured log lines.
Example: convert request logs into a counter metric for http_requests_total
with labels like method
, endpoint
, and status
.
This is ideal for:
- Log4j2 metrics extraction
- Logs-to-metrics pipelines
- Prometheus text metric generation from application logs
- Regex-based log analytics without external agents
<!-- OpenAI (default) -->
<LogGuardLayout
aiEnabled="true"
aiProvider="openai"
aiApiKey="${OPENAI_API_KEY}"
aiModel="gpt-3.5-turbo"
samplingRate="0.1"
extractMetrics="true"
batchSize="5"/>
<!-- Anthropic Claude -->
<LogGuardLayout
aiEnabled="true"
aiProvider="anthropic"
aiApiKey="${ANTHROPIC_API_KEY}"
aiModel="claude-3-sonnet-20240229"
samplingRate="0.1"
batchSize="5"/>
<!-- Azure OpenAI -->
<LogGuardLayout
aiEnabled="true"
aiProvider="azure-openai"
aiApiKey="${AZURE_OPENAI_API_KEY}"
aiModel="gpt-35-turbo"
azureEndpoint="https://your-resource.openai.azure.com"
azureDeployment="your-deployment-name"
azureApiVersion="2023-12-01"
samplingRate="0.1"
batchSize="5"/>
| Feature | v0.1 | v0.2 | v0.3 | v0.4 | v0.5 |
|---|---|---|---|---|---|
| Rule-Based Masking | |||||
| β | β | β | β | β | |
| AI Sanitization | |||||
| β | β | β | β | β | |
| LRU Caching | |||||
| β | β | β | β | β | |
| Batch Processing | |||||
| β | β | β | β | β | |
| Async/Non-Blocking | |||||
| β | β | β | β | β | |
| Multi-Provider AI | |||||
| β | β | β | β | β | |
| Metrics Extraction | |||||
| β | β | β | β | β (pattern-based) | |
| Latency | |||||
| <5ms | <5ms (rule-based) ~1500ms (API) <1ms (cached) | ||||
| <5ms guaranteed | <5ms guaranteed | <5ms guaranteed | |||
| Cost/10M logs | |||||
| $0 | $95 (no cache) $19 (with cache) | ||||
| $15-20 (with batching) | $15-20 (with batching) | $15-25 (depends on metrics config) | |||
| Dependencies | |||||
| 0 | 0 new | 0 new | 0 new | 0 new | |
| Backward Compatible | |||||
| N/A | β 100% | β 100% | β 100% | β 100% |
Logger logger = LoggerFactory.getLogger("MyApp");
// This will be automatically sanitized by LogGuardAI:
logger.info("User login: userId=12345 token=sk-abcdef123 password=secret");
// Output:
// User login: userId=***** token=***** password=*****
Development (AI Testing)
<LogGuardLayout aiEnabled="true" aiProvider="openai" samplingRate="0.05" aiTimeoutMs="1000" batchSize="3"/>
<!-- Or with Anthropic: aiProvider="anthropic" aiModel="claude-3-haiku-20240307" -->
Production (Balanced)
<LogGuardLayout aiEnabled="true" aiProvider="openai" samplingRate="0.1" aiTimeoutMs="2000" batchSize="5"/>
<!-- Or with Azure: aiProvider="azure-openai" azureEndpoint="..." azureDeployment="..." -->
High-Security (Premium)
<LogGuardLayout aiEnabled="true" aiProvider="openai" aiModel="gpt-4" samplingRate="1.0" batchSize="10"/>
<!-- Or with Claude: aiProvider="anthropic" aiModel="claude-3-sonnet-20240229" -->
Fast (No AI)
<LogGuardLayout aiEnabled="false"/> <!-- v0.1 behavior -->
β 5-minute setup (with AI examples)Quick Start Guideβ Deep dive into AI features (3000+ words)AI Integration Guideβ v0.1 β v0.2 upgrade pathMigration Guide
β All configuration optionsConfiguration Referenceβ Common issues & solutionsTroubleshootingβ Code organizationProject Structure
β How LogGuardAI worksSystem Overviewβ Detailed component descriptionsComponentsβ Interface referenceAIService API
β Complete version historyCHANGELOGβ v0.2 featuresv0.2.0 Release Notesβ Previous versionv0.1.0 Docs
β How to publishJitPack Publishing
// Transaction logs with credit card & billing info
logger.info("Transaction: user_id={} amount={} card={} crypto_key={}",
userId, amount, creditCard, encryptionKey);
// Automatically masked! β
// Auth logs with tokens & credentials
logger.info("Auth attempt: username={} password={} jwt_token={}",
username, password, jwtToken);
// All masked automatically! β
// Headers & API keys
logger.info("Incoming request: Authorization={} X-API-Key={} User-Agent={}",
bearerToken, apiKey, userAgent);
// Headers sanitized intelligently! β
Also: use metricsPatterns
to extract request counts, paths and status codes for lightweight in-app metrics collection.
Rule-Based Path: <5ms (fast, no external calls)
AI Hit (cached): <1ms (in-memory cache)
AI Miss (API): ~1.5s (to OpenAI, happens ~20% with 80% cache hit rate)
Without AI: $0/month (rule-based only)
With AI (no cache): $95/month (5% sampling)
With AI + caching: $19/month (5% sampling, 80% cache hits)
Savings: 80%
Rule-Based Only: >50,000 logs/sec
With AI Sampling: >45,000 logs/sec (minimal impact)
With Caching: >100,000 logs/sec (cached dominate)
β Secrets Never Exposed
- API keys, passwords, tokens, PII automatically masked
- Fail-safe: if LogGuard fails, logging still works (never breaks!)
- Timeout protection: no hanging requests
β API Key Protection
- API key stored in environment variable, never hardcoded
- No logs sent to external services (caching keeps results locally)
β Non-Blocking Design
-
Independent executor for AI calls
-
No thread blocking
-
Application never slows down
-
Java 8+
-
Maven 3.6+
mvn clean package
mvn test
ls target/logguardai-0.5.0.jar
| Version | Release Date | Status | What's New |
|---|---|---|---|
| v0.5.0 | |||
| 2026-05-27 | β Latest | Pattern-Based Metrics (user-defined regex metrics) | |
| v0.4.0 | |||
| 2026-05-03 | β Stable | Multi-Provider AI Support | |
| v0.3.0 | |||
| 2026-05-01 | β Stable | Plugin Registration Fix | |
| v0.2.0 | |||
| 2026-04-23 | β Stable | AI + Caching | |
| v0.1.0 | |||
| 2026-04-22 | β Stable | Rule-based masking |
β See CHANGELOG for complete history
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
Questions?GitHub Discussions** Report Issues:GitHub Issues Full Documentation:**docs/README.md
MIT License - See LICENSE for details
Get StartedβQuick Start Guide** Enable AIβAI Integration Guide ConfigureβConfiguration Reference Troubleshoot**βTroubleshooting Guide
LogGuardAI: Secure your logs. Automatically.
Built with β€οΈ by sanitizeai