Skip to content

Commit

Permalink
FISH-9456: Allow LogDomains to use LogMessages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Viii3 committed Aug 28, 2024
1 parent a0f9aa9 commit f5a7bb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private LogDomains() {}
*/
public static final String RESOURCE_BUNDLE = "LogStrings";

public static final String RESOURCE_BUNDLE_MESSAGES = "LogMessages";

/**
* Field
*/
Expand Down Expand Up @@ -363,26 +365,33 @@ public static Logger getLogger(final Class clazz, final String namePrefix, final
return logManager.getLogger(cLogger.getName());
}

private static ResourceBundle getResourceBundle(final String name, final Class clazz,
final ClassLoader resourceBundleLoader) {
final ResourceBundle classBundle = findResourceBundle(name, clazz, resourceBundleLoader);
private static ResourceBundle getResourceBundle (final String name, final Class<?> clazz, final ClassLoader resourceBundleLoader) {
ResourceBundle classBundle = findResourceBundle(name, clazz, resourceBundleLoader);
if (classBundle == null) { // EJB uses LogMessages instead of LogStrings, check for this file if necessary.
classBundle = findResourceBundle(name, clazz, resourceBundleLoader, RESOURCE_BUNDLE_MESSAGES);
}

if (classBundle != null) {
return classBundle;
}

Logger.getAnonymousLogger().log(Level.INFO, "Cannot find the resource bundle for the name {0} for {1} using {2}", new Object[]{name, clazz, resourceBundleLoader});
return null;
}

private static ResourceBundle findResourceBundle(final String name, final Class clazz,
final ClassLoader classLoader) {
final ResourceBundle packageRootBundle = tryTofindResourceBundle(name, classLoader);
private static ResourceBundle findResourceBundle (final String name, final Class<?> clazz, final ClassLoader classLoader) {
return findResourceBundle(name, clazz, classLoader, LogDomains.RESOURCE_BUNDLE);
}

private static ResourceBundle findResourceBundle (final String name, final Class<?> clazz, final ClassLoader classLoader, final String fileSuffix) {
final ResourceBundle packageRootBundle = tryToFindResourceBundle(name, classLoader, fileSuffix);
if (packageRootBundle != null) {
return packageRootBundle;
}
// not found. Ok, let's try to go through the class's package tree
final StringBuilder rbPackage = new StringBuilder(clazz.getPackage().getName());
while (true) {
final ResourceBundle subPkgBundle = tryTofindResourceBundle(rbPackage.toString(), classLoader);
final ResourceBundle subPkgBundle = tryToFindResourceBundle(rbPackage.toString(), classLoader, fileSuffix);
if (subPkgBundle != null) {
return subPkgBundle;
}
Expand All @@ -402,9 +411,9 @@ private static String getLoggerName(Class clazz, String logDomainsConstantName)
return loggerName;
}

private static ResourceBundle tryTofindResourceBundle(final String name, final ClassLoader classLoader) {
private static ResourceBundle tryToFindResourceBundle (final String name, final ClassLoader classLoader, final String fileSuffix) {
try {
return ResourceBundle.getBundle(name + "." + LogDomains.RESOURCE_BUNDLE, Locale.getDefault(), classLoader);
return ResourceBundle.getBundle(name + "." + fileSuffix, Locale.getDefault(), classLoader);
} catch (MissingResourceException e) {
return null;
}
Expand Down

0 comments on commit f5a7bb7

Please sign in to comment.