Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
destan committed Nov 26, 2019
1 parent 459c7db commit 3c9f90b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected Object handleGetObject(String key) {

@Override
public Enumeration<String> getKeys() {
ResourceBundle parent = this.parent;
final ResourceBundle parent = this.parent;
return new ResourceBundleEnumeration(lookup.keySet(), parent != null ? parent.getKeys() : null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C

final String bundleName = super.toBundleName(baseName, locale);
final Map<String, Object> 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);
}

Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public DefaultBundleContentLoaderStrategy(DataSource dataSource, String loadQuer

@Override
public Map<String, Object> 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();
Expand All @@ -108,7 +113,7 @@ public Map<String, Object> 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()) {
Expand All @@ -120,6 +125,10 @@ public Map<String, Object> 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;
}
}
Expand All @@ -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()) {
Expand Down

0 comments on commit 3c9f90b

Please sign in to comment.