From c85931cbc54bb08b7caaa17a0fece6ab17d5726e Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 23 Mar 2011 02:22:19 +0000
Subject: [PATCH] log tweaks

---
 .../java/src/net/i2p/addressbook/Daemon.java         |  9 ++++++---
 .../java/src/net/i2p/addressbook/DaemonThread.java   |  1 +
 .../i2p/client/naming/BlockfileNamingService.java    | 12 +++++-------
 .../src/net/i2p/client/naming/NamingService.java     |  2 +-
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java
index 50f2c9fd52..0e9a314a03 100644
--- a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java
+++ b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java
@@ -126,10 +126,11 @@ public class Daemon {
             long start = System.currentTimeMillis();
             AddressBook sub = iter.next();
             long end = System.currentTimeMillis();
-            if (DEBUG && log != null)
+            // SubscriptionIterator puts in a dummy AddressBook with no location if no fetch is done
+            if (DEBUG && log != null && sub.getLocation() != null)
                 log.append("Fetch of " + sub.getLocation() + " took " + (end - start));
             start = end;
-            int old = 0, nnew = 0, invalid = 0, conflict = 0;
+            int old = 0, nnew = 0, invalid = 0, conflict = 0, total = 0;
             for (Iterator<Map.Entry<String, String>> eIter = sub.iterator(); eIter.hasNext(); ) {
                 Map.Entry<String, String> entry = eIter.next();
                 String key = entry.getKey();
@@ -197,10 +198,12 @@ public class Daemon {
                         log.append("Invalid b64 for" + key + " From: " + sub.getLocation());
                     invalid++;
                 }
+                total++;
             }
-            if (DEBUG && log != null) {
+            if (DEBUG && log != null && total > 0) {
                 log.append("Merge of " + sub.getLocation() + " into " + router +
                            " took " + (System.currentTimeMillis() - start) + " ms with " +
+                           total + " total, " +
                            nnew + " new, " +
                            old + " old, " +
                            invalid + " invalid, " +
diff --git a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java
index 44592f8ef5..01597e765f 100644
--- a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java
+++ b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java
@@ -66,6 +66,7 @@ class DaemonThread extends Thread implements NamingServiceUpdater {
 
     /**
      *  The NamingServiceUpdater interface
+     *  @param options ignored
      *  @since 0.8.6
      */
     public void update(Properties options) {
diff --git a/core/java/src/net/i2p/client/naming/BlockfileNamingService.java b/core/java/src/net/i2p/client/naming/BlockfileNamingService.java
index 9637215956..b19a211db3 100644
--- a/core/java/src/net/i2p/client/naming/BlockfileNamingService.java
+++ b/core/java/src/net/i2p/client/naming/BlockfileNamingService.java
@@ -202,9 +202,10 @@ public class BlockfileNamingService extends DummyNamingService {
             if (_log.shouldLog(Log.INFO))
                 _log.info("DB init took " + DataHelper.formatDuration(_context.clock().now() - start));
             if (total <= 0)
-                _log.error("Warning - initialized database with zero entries");
+                _log.logAlways(Log.WARN, "No hosts.txt files found, Initialized hosts database with zero entries");
             return rv;
         } catch (RuntimeException e) {
+            _log.error("Failed to initialize database", e);
             throw new IOException(e.toString());
         }
     }
@@ -245,9 +246,11 @@ public class BlockfileNamingService extends DummyNamingService {
             if (skiplists.isEmpty())
                 skiplists.add(FALLBACK_LIST);
             _lists.addAll(skiplists);
-            _log.error("DB init took " + DataHelper.formatDuration(_context.clock().now() - start));
+            if (_log.shouldLog(Log.INFO))
+                _log.info("DB init took " + DataHelper.formatDuration(_context.clock().now() - start));
             return bf;
         } catch (RuntimeException e) {
+            _log.error("Failed to initialize database", e);
             throw new IOException(e.toString());
         }
     }
@@ -262,8 +265,6 @@ public class BlockfileNamingService extends DummyNamingService {
             if (sl == null)
                 return null;
             DestEntry rv = (DestEntry) sl.get(key);
-            // Control memory usage
-////////    _bf.closeIndex(listname);
             return rv;
         } catch (IOException ioe) {
             _log.error("DB Lookup error", ioe);
@@ -292,8 +293,6 @@ public class BlockfileNamingService extends DummyNamingService {
             if (source != null)
                 props.setProperty(PROP_SOURCE, source);
             addEntry(sl, key, dest, props);
-            // Control memory usage
-//////      bf.closeIndex(listname);
         } catch (IOException ioe) {
             _log.error("DB add error", ioe);
             // delete index??
@@ -752,7 +751,6 @@ public class BlockfileNamingService extends DummyNamingService {
 
     public static void main(String[] args) {
         BlockfileNamingService bns = new BlockfileNamingService(I2PAppContext.getGlobalContext());
-        //System.out.println("zzz.i2p: " + bns.lookup("zzz.i2p"));
         List<String> names = null;
         try {
             Properties props = new Properties();
diff --git a/core/java/src/net/i2p/client/naming/NamingService.java b/core/java/src/net/i2p/client/naming/NamingService.java
index ba26d45ed0..b9ffd62993 100644
--- a/core/java/src/net/i2p/client/naming/NamingService.java
+++ b/core/java/src/net/i2p/client/naming/NamingService.java
@@ -432,7 +432,7 @@ public abstract class NamingService {
             instance = (NamingService)con.newInstance(new Object[] { context });
         } catch (Exception ex) {
             Log log = context.logManager().getLog(NamingService.class);
-            log.error("Cannot load naming service " + impl, ex);
+            log.error("Cannot load naming service " + impl + ", only .b32.i2p lookups will succeed", ex);
             instance = new DummyNamingService(context); // fallback
         }
         return instance;
-- 
GitLab