From 3c9f90bb40d42d188f2d0645170023fa3f0369f4 Mon Sep 17 00:00:00 2001 From: Destan Sarpkaya Date: Tue, 26 Nov 2019 12:01:29 +0300 Subject: [PATCH] improved logging --- .../DatabaseResourceBundle.java | 2 +- .../DatabaseResourceBundleControl.java | 13 ++++++++++++- .../DefaultBundleContentLoaderStrategy.java | 13 +++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundle.java b/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundle.java index 9d89c1f..e75baf2 100644 --- a/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundle.java +++ b/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundle.java @@ -59,7 +59,7 @@ protected Object handleGetObject(String key) { @Override public Enumeration getKeys() { - ResourceBundle parent = this.parent; + final ResourceBundle parent = this.parent; return new ResourceBundleEnumeration(lookup.keySet(), parent != null ? parent.getKeys() : null); } diff --git a/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundleControl.java b/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundleControl.java index c82e401..aa126ec 100644 --- a/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundleControl.java +++ b/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DatabaseResourceBundleControl.java @@ -80,6 +80,11 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C final String bundleName = super.toBundleName(baseName, locale); final Map lookup = loadFromDatabase(bundleName); + + if (log.isTraceEnabled()) { + log.trace("New bundle with size '{}' for baseName '{}', locale '{}', format '{}', reload '{}'", lookup.size(), baseName, locale, format, reload); + } + return lookup.isEmpty() ? null : new DatabaseResourceBundle(lookup); } @@ -96,7 +101,13 @@ public long getTimeToLive(@NonNull String baseName, @NonNull Locale locale) { */ @Override public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, @NonNull ResourceBundle bundle, long loadTime) { - return this.bundleContentLoaderStrategy.needsReload(baseName, locale, format, bundle, loadTime); + final boolean needsReload = this.bundleContentLoaderStrategy.needsReload(baseName, locale, format, bundle, loadTime); + + if (log.isTraceEnabled()) { + log.trace("Needs reload is '{}' for baseName '{}', locale '{}', format '{}', bundle '{}', loadTime '{}'", needsReload, baseName, locale, format, bundle, loadTime); + } + + return needsReload; } /** diff --git a/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DefaultBundleContentLoaderStrategy.java b/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DefaultBundleContentLoaderStrategy.java index d96561c..91f9f61 100644 --- a/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DefaultBundleContentLoaderStrategy.java +++ b/src/main/java/com/kodgemisi/cigdem/databaseresourcbundle/DefaultBundleContentLoaderStrategy.java @@ -97,6 +97,11 @@ public DefaultBundleContentLoaderStrategy(DataSource dataSource, String loadQuer @Override public Map loadFromDatabase(String bundleName) { + + if (log.isTraceEnabled()) { + log.trace("Loading from database for bundle with baseName '{}'", bundleName); + } + final BundleMetaData bundleMetaData = new BundleMetaData(bundleName); try (final Connection connection = dataSource.getConnection(); @@ -108,7 +113,7 @@ public Map loadFromDatabase(String bundleName) { preparedStatement.setString(4, bundleMetaData.variant); if (log.isTraceEnabled()) { - log.trace("Loading content for {} with query {}", bundleName, preparedStatement); + log.trace("Loading content for bundle baseName '{}' with query '{}'", bundleName, preparedStatement); } try (final ResultSet resultSet = preparedStatement.executeQuery()) { @@ -120,6 +125,10 @@ public Map loadFromDatabase(String bundleName) { resultMap.put(key, value); } + if (log.isDebugEnabled()) { + log.debug("Bundle with baseName '{}' is loaded from database. Size {}", bundleName, resultMap.size()); + } + return resultMap; } } @@ -138,7 +147,7 @@ public boolean needsReload(String baseName, Locale locale, String format, Resour preparedStatement.setString(1, baseName); if (log.isTraceEnabled()) { - log.trace("Checking if reload needed content for {} {} with query {}", baseName, locale, preparedStatement); + log.trace("Checking if reload needed for baseName '{}' and locale '{}' with query '{}'", baseName, locale, preparedStatement); } try (final ResultSet resultSet = preparedStatement.executeQuery()) {