From 3a7092e48f27cba6286946442783f539ad73a911 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 20 Jul 2015 06:35:53 +0200 Subject: [PATCH] =?utf8?q?Abandon=20logging=20that=20does=20not=20work=20w?= =?utf8?q?ith=20Freenet=E2=80=99s=20logger=20at=20all?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 2 +- .../pterodactylus/sone/core/FreenetInterface.java | 2 +- .../net/pterodactylus/sone/core/ImageInserter.java | 2 +- .../sone/core/SoneDownloaderImpl.java | 2 +- .../net/pterodactylus/sone/core/SoneInserter.java | 2 +- .../net/pterodactylus/sone/core/SoneParser.java | 2 +- .../java/net/pterodactylus/sone/core/SoneUri.java | 2 +- .../net/pterodactylus/sone/core/UpdateChecker.java | 2 +- .../sone/core/WebOfTrustUpdaterImpl.java | 2 +- .../net/pterodactylus/sone/data/impl/SoneImpl.java | 2 +- .../sone/database/memory/ConfigurationLoader.java | 3 +- .../net/pterodactylus/sone/fcp/FcpInterface.java | 2 +- .../freenet/PluginStoreConfigurationBackend.java | 2 +- .../sone/freenet/wot/IdentityManagerImpl.java | 2 +- .../sone/freenet/wot/WebOfTrustConnector.java | 2 +- .../net/pterodactylus/sone/main/SonePlugin.java | 38 +++++++++++----------- .../pterodactylus/sone/template/SoneAccessor.java | 2 +- .../pterodactylus/sone/text/SoneTextParser.java | 2 +- .../net/pterodactylus/sone/web/CreateSonePage.java | 2 +- .../java/net/pterodactylus/sone/web/LoginPage.java | 2 +- .../net/pterodactylus/sone/web/SearchPage.java | 2 +- .../pterodactylus/sone/web/UploadImagePage.java | 2 +- .../net/pterodactylus/sone/web/WebInterface.java | 2 +- .../net/pterodactylus/sone/web/ajax/JsonPage.java | 2 +- .../sone/web/page/FreenetTemplatePage.java | 2 +- 25 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 73bb95f..e70f963 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -116,7 +116,7 @@ import com.google.inject.Singleton; public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider { /** The logger. */ - private static final Logger logger = getLogger("Sone.Core"); + private static final Logger logger = getLogger(Core.class.getName()); /** The start time. */ private final long startupTime = System.currentTimeMillis(); diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index e802ba2..81ed069 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -76,7 +76,7 @@ import freenet.support.io.ResumeFailedException; public class FreenetInterface { /** The logger. */ - private static final Logger logger = getLogger("Sone.FreenetInterface"); + private static final Logger logger = getLogger(FreenetInterface.class.getName()); /** The event bus. */ private final EventBus eventBus; diff --git a/src/main/java/net/pterodactylus/sone/core/ImageInserter.java b/src/main/java/net/pterodactylus/sone/core/ImageInserter.java index 25362a6..6b33897 100644 --- a/src/main/java/net/pterodactylus/sone/core/ImageInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/ImageInserter.java @@ -44,7 +44,7 @@ import com.google.common.base.Function; public class ImageInserter { /** The logger. */ - private static final Logger logger = getLogger("Sone.Image.Inserter"); + private static final Logger logger = getLogger(ImageInserter.class.getName()); /** The freenet interface. */ private final FreenetInterface freenetInterface; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java index b36c2d3..df5d0c1 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java @@ -54,7 +54,7 @@ import com.google.common.annotations.VisibleForTesting; public class SoneDownloaderImpl extends AbstractService implements SoneDownloader { /** The logger. */ - private static final Logger logger = getLogger("Sone.Downloader"); + private static final Logger logger = getLogger(SoneDownloaderImpl.class.getName()); /** The maximum protocol version. */ private static final int MAX_PROTOCOL_VERSION = 0; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 86bf049..45c617c 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -79,7 +79,7 @@ import freenet.support.io.ArrayBucket; public class SoneInserter extends AbstractService { /** The logger. */ - private static final Logger logger = getLogger("Sone.Inserter"); + private static final Logger logger = getLogger(SoneInserter.class.getName()); /** The insertion delay (in seconds). */ private static final AtomicInteger insertionDelay = new AtomicInteger(60); diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index ae600a6..2712bd3 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -38,7 +38,7 @@ import org.w3c.dom.Document; */ public class SoneParser { - private static final Logger logger = getLogger("Sone.Parser"); + private static final Logger logger = getLogger(SoneParser.class.getName()); private static final int MAX_PROTOCOL_VERSION = 0; private final Core core; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneUri.java b/src/main/java/net/pterodactylus/sone/core/SoneUri.java index ea84b39..eeab32b 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneUri.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneUri.java @@ -34,7 +34,7 @@ import freenet.keys.FreenetURI; public class SoneUri { /** The logger. */ - private static final Logger logger = getLogger("Sone.Data"); + private static final Logger logger = getLogger(SoneUri.class.getName()); /** * Generate a Sone URI from the given URI. diff --git a/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java b/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java index 8114118..e24032f 100644 --- a/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java +++ b/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java @@ -48,7 +48,7 @@ import freenet.support.api.Bucket; public class UpdateChecker { /** The logger. */ - private static final Logger logger = getLogger("Sone.UpdateChecker"); + private static final Logger logger = getLogger(UpdateChecker.class.getName()); /** The event bus. */ private final EventBus eventBus; diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java index 56bd8c9..9aa6dec 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdaterImpl.java @@ -47,7 +47,7 @@ import com.google.inject.Singleton; public class WebOfTrustUpdaterImpl extends AbstractService implements WebOfTrustUpdater { /** The logger. */ - private static final Logger logger = getLogger("Sone.WoT.Updater"); + private static final Logger logger = getLogger(WebOfTrustUpdaterImpl.class.getName()); /** Stop job. */ @SuppressWarnings("synthetic-access") diff --git a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java index 2fdd40c..f7ebfb1 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java @@ -59,7 +59,7 @@ import com.google.common.hash.Hashing; public class SoneImpl implements Sone { /** The logger. */ - private static final Logger logger = getLogger("Sone.Data"); + private static final Logger logger = getLogger(SoneImpl.class.getName()); /** The database. */ private final Database database; diff --git a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java index 1691ddb..0f55575 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java @@ -17,8 +17,7 @@ import net.pterodactylus.util.config.ConfigurationException; */ public class ConfigurationLoader { - private static final Logger logger = - Logger.getLogger("Sone.Database.Memory.Configuration"); + private static final Logger logger = Logger.getLogger(ConfigurationLoader.class.getName()); private final Configuration configuration; public ConfigurationLoader(Configuration configuration) { diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 839930c..5612a4f 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -75,7 +75,7 @@ public class FcpInterface { } /** The logger. */ - private static final Logger logger = getLogger("Sone.External.Fcp"); + private static final Logger logger = getLogger(FcpInterface.class.getName()); /** Whether the FCP interface is currently active. */ private final AtomicBoolean active = new AtomicBoolean(); diff --git a/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java b/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java index eb16a09..eec8aa3 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java +++ b/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java @@ -38,7 +38,7 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac /** The logger. */ @SuppressWarnings("unused") - private static final Logger logger = getLogger("Sone.Fred"); + private static final Logger logger = getLogger(PluginStoreConfigurationBackend.class.getName()); /** The plugin respirator. */ private final PluginRespirator pluginRespirator; diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java index 4c94749..70071f1 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java @@ -50,7 +50,7 @@ import com.google.inject.Singleton; public class IdentityManagerImpl extends AbstractService implements IdentityManager { /** The logger. */ - private static final Logger logger = getLogger("Sone.Identities"); + private static final Logger logger = getLogger(IdentityManagerImpl.class.getName()); /** The event bus. */ private final EventBus eventBus; diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index 3b30a4e..9ac5dd4 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -50,7 +50,7 @@ import freenet.support.api.Bucket; public class WebOfTrustConnector { /** The logger. */ - private static final Logger logger = getLogger("Sone.WoT.Connector"); + private static final Logger logger = getLogger(WebOfTrustConnector.class.getName()); /** The name of the WoT plugin. */ private static final String WOT_PLUGIN_NAME = "plugins.WebOfTrust.WebOfTrust"; diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index b80aa47..17340b8 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -27,21 +27,9 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; -import net.pterodactylus.sone.core.FreenetInterface; -import net.pterodactylus.sone.core.WebOfTrustUpdater; -import net.pterodactylus.sone.core.WebOfTrustUpdaterImpl; -import net.pterodactylus.sone.database.Database; -import net.pterodactylus.sone.database.PostBuilderFactory; -import net.pterodactylus.sone.database.PostProvider; -import net.pterodactylus.sone.database.PostReplyBuilderFactory; -import net.pterodactylus.sone.database.SoneProvider; -import net.pterodactylus.sone.database.memory.MemoryDatabase; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend; -import net.pterodactylus.sone.freenet.plugin.PluginConnector; import net.pterodactylus.sone.freenet.wot.Context; -import net.pterodactylus.sone.freenet.wot.IdentityManager; -import net.pterodactylus.sone.freenet.wot.IdentityManagerImpl; import net.pterodactylus.sone.freenet.wot.WebOfTrustConnector; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.util.config.Configuration; @@ -50,6 +38,9 @@ import net.pterodactylus.util.config.MapConfigurationBackend; import net.pterodactylus.util.version.Version; import com.google.common.base.Optional; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.eventbus.EventBus; import com.google.inject.AbstractModule; import com.google.inject.Guice; @@ -86,22 +77,31 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr static { /* initialize logging. */ - Logger soneLogger = getLogger("Sone"); + Logger soneLogger = getLogger("net.pterodactylus.sone"); soneLogger.setUseParentHandlers(false); soneLogger.addHandler(new Handler() { + private final LoadingCache> classCache = CacheBuilder.newBuilder() + .build(new CacheLoader>() { + @Override + public Class load(String key) throws Exception { + return Class.forName(key); + } + }); + @Override public void publish(LogRecord logRecord) { int recordLevel = logRecord.getLevel().intValue(); + Class loggingClass = classCache.getUnchecked(logRecord.getLoggerName()); if (recordLevel < Level.FINE.intValue()) { - freenet.support.Logger.debug(logRecord.getLoggerName(), logRecord.getMessage(), logRecord.getThrown()); + freenet.support.Logger.debug(loggingClass, logRecord.getMessage(), logRecord.getThrown()); } else if (recordLevel < Level.INFO.intValue()) { - freenet.support.Logger.minor(logRecord.getLoggerName(), logRecord.getMessage(), logRecord.getThrown()); + freenet.support.Logger.minor(loggingClass, logRecord.getMessage(), logRecord.getThrown()); } else if (recordLevel < Level.WARNING.intValue()) { - freenet.support.Logger.normal(logRecord.getLoggerName(), logRecord.getMessage(), logRecord.getThrown()); + freenet.support.Logger.normal(loggingClass, logRecord.getMessage(), logRecord.getThrown()); } else if (recordLevel < Level.SEVERE.intValue()) { - freenet.support.Logger.warning(logRecord.getLoggerName(), logRecord.getMessage(), logRecord.getThrown()); + freenet.support.Logger.warning(loggingClass, logRecord.getMessage(), logRecord.getThrown()); } else { - freenet.support.Logger.error(logRecord.getLoggerName(), logRecord.getMessage(), logRecord.getThrown()); + freenet.support.Logger.error(loggingClass, logRecord.getMessage(), logRecord.getThrown()); } } @@ -124,7 +124,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr private static final int LATEST_EDITION = 69; /** The logger. */ - private static final Logger logger = getLogger("Sone.Plugin"); + private static final Logger logger = getLogger(SonePlugin.class.getName()); /** The plugin respirator. */ private PluginRespirator pluginRespirator; diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index 711332a..03973a1 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -58,7 +58,7 @@ import net.pterodactylus.util.template.TemplateContext; public class SoneAccessor extends ReflectionAccessor { /** The logger. */ - private static final Logger logger = getLogger("Sone.Data"); + private static final Logger logger = getLogger(SoneAccessor.class.getName()); /** The core. */ private final Core core; diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index cc5c59b..b85f100 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -47,7 +47,7 @@ import freenet.keys.FreenetURI; public class SoneTextParser implements Parser { /** The logger. */ - private static final Logger logger = getLogger("Sone.Data.Parser"); + private static final Logger logger = getLogger(SoneTextParser.class.getName()); /** Pattern to detect whitespace. */ private static final Pattern whitespacePattern = Pattern.compile("[\\u000a\u0020\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u200c\u200d\u202f\u205f\u2060\u2800\u3000]"); diff --git a/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java b/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java index b2d4578..ef2d619 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java @@ -44,7 +44,7 @@ import freenet.clients.http.ToadletContext; public class CreateSonePage extends SoneTemplatePage { /** The logger. */ - private static final Logger logger = getLogger("Sone.Web.CreateSone"); + private static final Logger logger = getLogger(CreateSonePage.class.getName()); /** * Creates a new “create Sone” page. diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index 58e33a1..b5c608c 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -41,7 +41,7 @@ public class LoginPage extends SoneTemplatePage { /** The logger. */ @SuppressWarnings("unused") - private static final Logger logger = getLogger("Sone.Web.Login"); + private static final Logger logger = getLogger(LoginPage.class.getName()); /** * Creates a new login page. diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 3efba95..95b0bba 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -64,7 +64,7 @@ import com.google.common.collect.Ordering; public class SearchPage extends SoneTemplatePage { /** The logger. */ - private static final Logger logger = getLogger("Sone.Web.Search"); + private static final Logger logger = getLogger(SearchPage.class.getName()); /** Short-term cache. */ private final LoadingCache, Set>> hitCache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(new CacheLoader, Set>>() { diff --git a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java index 5e23a78..30a5890 100644 --- a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java @@ -56,7 +56,7 @@ import freenet.support.api.HTTPUploadedFile; public class UploadImagePage extends SoneTemplatePage { /** The logger. */ - private static final Logger logger = getLogger("Sone.Web.UploadImage"); + private static final Logger logger = getLogger(UploadImagePage.class.getName()); /** * Creates a new “upload image” page. diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index e813179..fbba8e0 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -174,7 +174,7 @@ import freenet.support.api.HTTPRequest; public class WebInterface { /** The logger. */ - private static final Logger logger = getLogger("Sone.Web.Main"); + private static final Logger logger = getLogger(WebInterface.class.getName()); /** The notification manager. */ private final NotificationManager notificationManager = new NotificationManager(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java index 6d6d92a..2392b12 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java @@ -48,7 +48,7 @@ import freenet.clients.http.ToadletContext; public abstract class JsonPage implements FreenetPage { /** The logger. */ - private static final Logger logger = getLogger("Sone.Web.Ajax"); + private static final Logger logger = getLogger(JsonPage.class.getName()); /** The JSON serializer. */ private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java index 40e19b1..5e30ca0 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java @@ -52,7 +52,7 @@ import freenet.support.HTMLNode; public class FreenetTemplatePage implements FreenetPage, LinkEnabledCallback { /** The logger. */ - private static final Logger logger = getLogger("Sone.Web.Freenet"); + private static final Logger logger = getLogger(FreenetTemplatePage.class.getName()); /** The path of the page. */ private final String path; -- 2.7.4