Skip to content

Commit

Permalink
Issue eclipse-ee4j#23873 Fix for quicklook tests - LogDomains vs. bun…
Browse files Browse the repository at this point in the history
…dles

- for some unknown reason tests fail when we use standard of JDK8+ for
  setting a resource bundle to a logger. I couldn't find the exact cause
  of the failure (invalid tx state) now, but I will get back to it later
  after jta/jps refactoring and also with new logging it should be easier.
  That is why I added the FIXME here - and also to prevent me or someone
  else breaking it again.
  • Loading branch information
dmatej committed Jul 16, 2022
1 parent ce6321a commit fd75f94
Showing 1 changed file with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import static java.util.logging.Level.CONFIG;
import static java.util.logging.Level.FINEST;
import static java.util.logging.Level.WARNING;

/**
Expand Down Expand Up @@ -347,6 +350,7 @@ public static Logger getLogger(final Class<?> clazz, final String loggerNamePref
final String loggerName = loggerNamePrefix + "." + clazz.getPackageName();
final Logger cachedLogger = MANAGER.getLogger(loggerName);
if (cachedLogger != null) {
LOG.log(FINEST, "Cached logger: {0}", cachedLogger);
return cachedLogger;
}

Expand All @@ -364,6 +368,7 @@ public static Logger getLogger(final Class<?> clazz, final String loggerNamePref
// a race condition has already created one
boolean added = MANAGER.addLogger(newLogger);
if (added) {
LOG.log(CONFIG, "Registered new logger: {0}", newLogger);
return newLogger;
}

Expand Down Expand Up @@ -427,11 +432,39 @@ private static ResourceBundle tryTofindResourceBundle(final String name, final C

private static class LogDomainsLogger extends Logger {

// FIXME: setResourceBundle doesn't work for some reason, breaks
// test.jms.injection.ClientTestNG.testTransactionScopedJMSContextInjection
// As GF swallows exceptions in critical code, it is hard to find out why.
private final ResourceBundle resourceBundle;

public LogDomainsLogger(String loggerName, ResourceBundle resourceBundle) {
super(loggerName, null);
if (resourceBundle != null) {
setResourceBundle(resourceBundle);
}
this.resourceBundle = resourceBundle;
}


@Override
public void log(LogRecord record) {
record.setResourceBundle(resourceBundle);
super.log(record);
}


@Override
public ResourceBundle getResourceBundle() {
return this.resourceBundle;
}


@Override
public String getResourceBundleName() {
return resourceBundle == null ? null : resourceBundle.getBaseBundleName();
}


@Override
public String toString() {
return super.toString() + "[name=" + getName() + ", bundleName=" + getResourceBundleName() + "]";
}
}
}

0 comments on commit fd75f94

Please sign in to comment.