From ba34caf8fceeef587943077d3b6404ee57045982 Mon Sep 17 00:00:00 2001 From: Slatian Date: Sun, 9 Feb 2025 16:27:12 +0100 Subject: [PATCH] Log not found errors to the debug channel They are part of normal operation and shouldn't be logged in production. --- src/geoip.rs | 21 +++++++++++++++++---- src/ipinfo.rs | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/geoip.rs b/src/geoip.rs index 5e07f71..64fa7ee 100644 --- a/src/geoip.rs +++ b/src/geoip.rs @@ -3,9 +3,10 @@ * that provides the results ready for templating. */ -use log::{info,warn,error}; +use log::{debug,info,warn,error}; use maxminddb::geoip2; +use maxminddb::MaxMindDBError::AddressNotFoundError; use parking_lot::RwLock; use std::collections::BTreeMap; @@ -135,9 +136,15 @@ impl QueryAsn for MMDBCarrier { name: res.autonomous_system_organization.map(ToString::to_string), }) }, + Err(AddressNotFoundError(_)) => { + // Log to the debug channel. + // This isn't severe, and shouldn't be logged in production. + debug!("ASN not found in database for {address}."); + None + }, Err(e) => { error!("Error while looking up ASN for {address}: {e}"); - Default::default() + None } } }, @@ -203,9 +210,15 @@ impl QueryLocation for MMDBCarrier { }, }) }, + Err(AddressNotFoundError(_)) => { + // Log to the debug channel. + // This isn't severe, and shouldn't be logged in production. + debug!("IP location not found in database for {address}"); + None + }, Err(e) => { - error!("Error while looking up ASN for {address}: {e}"); - Default::default() + error!("Error while looking up IP location for {address}: {e}"); + None } } }, diff --git a/src/ipinfo.rs b/src/ipinfo.rs index 5a2660f..5427c44 100644 --- a/src/ipinfo.rs +++ b/src/ipinfo.rs @@ -111,6 +111,7 @@ impl AddressInfo { scope: address_scope } } + }