Reducing Log Noise: Filtering What Matters
Drowning in logs? Learn how to filter out noise and focus on what actually helps you debug.
More logs don't mean better debugging. In fact, excessive logging often makes debugging harder—important errors get buried in noise. Here's how to filter out the cruft and focus on what matters.
Signs You Have Too Much Noise
- You scroll past hundreds of logs to find errors
- Searches return thousands of results
- You've stopped looking at logs because there's too much
- Important alerts get lost in notification floods
- Log costs are disproportionate to log value
Common Sources of Noise
1. Health Checks
Load balancers and monitoring systems hitting /health every few seconds:
// Filter these out
if ($request->is('health', 'healthz', 'ping')) {
return $next($request); // Don't log
}
2. Static Assets
Requests for CSS, JS, images that your web server should handle:
# nginx.conf - Don't send to app
location ~* \.(css|js|png|jpg|gif|ico)$ {
access_log off;
}
3. Successful Routine Operations
Do you really need to log every successful database query?
// Bad: Logs every query
DB::listen(function ($query) {
Log::info('Query executed', ['sql' => $query->sql]);
});
// Better: Log only slow queries
DB::listen(function ($query) {
if ($query->time > 1000) {
Log::warning('Slow query', ['sql' => $query->sql, 'time' => $query->time]);
}
});
4. Expected Errors
Some "errors" are actually normal:
- 404s for favicon.ico, robots.txt
- Validation failures from user input
- Rate limit rejections (log aggregated stats instead)
Filtering Strategies
1. Log Levels
Use appropriate levels and filter in production:
# Production
LOG_LEVEL=warning # Only warning and above
# Development
LOG_LEVEL=debug # Everything
2. Exception Filtering
// app/Exceptions/Handler.php
protected $dontReport = [
AuthenticationException::class,
ValidationException::class,
ModelNotFoundException::class,
];
3. Conditional Logging
// Only log in specific conditions
if (config('app.debug') || $response->isServerError()) {
Log::info('Request completed', $context);
}
4. Sampling
// Log 1% of successful events
public function logWithSampling(string $message, array $context, int $sampleRate = 100): void
{
if (rand(1, $sampleRate) === 1) {
Log::info($message, $context);
}
}
What to Always Log
Never filter out:
- Errors and exceptions
- Security events (failed logins, permission denials)
- Payment/transaction events
- Data modifications (audit trail)
- Integration failures (third-party APIs)
Before and After
| Metric | Before | After |
|---|---|---|
| Logs per day | 10M | 500K |
| Time to find errors | Minutes | Seconds |
| Monthly cost | $150 | $20 |
| Alert fatigue | High | Low |
Conclusion
Effective logging isn't about capturing everything—it's about capturing the right things. Aggressive filtering makes your logs more useful, cheaper, and actually readable.
Start by removing obvious noise, then iteratively filter more based on what you actually use.
Admin
Published on November 17, 2025