Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public final class CommonI18n {

public static I18n errorInitializingCustomLoggerFactory;

public static I18n customLoggingAvailable;
public static I18n slf4jAvailable;
public static I18n log4jAvailable;
public static I18n jdkFallback;

static {
try {
I18n.initialize(CommonI18n.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@
@ThreadSafe
public final class I18n implements I18nResource {

private static final Logger LOGGER = Logger.getLogger(I18n.class);

/**
* The first level of this map indicates whether an i18n class has been localized to a particular locale. The second level
* contains any problems encountered during localization.
*
* Make sure this is always the first member in the class because it must be initialized *before* the Logger (see below).
* Otherwise it's possible to trigger a NPE because of nested initializers.
*/
static final ConcurrentMap<Locale, Map<Class<?>, Set<String>>> LOCALE_TO_CLASS_TO_PROBLEMS_MAP = new ConcurrentHashMap<Locale, Map<Class<?>, Set<String>>>();

private static final Logger LOGGER = Logger.getLogger(I18n.class);

/**
* Note, calling this method will <em>not</em> trigger localization of the supplied internationalization class.
Expand Down Expand Up @@ -422,9 +424,6 @@ public String text( Locale locale,
}
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.modeshape.common.logging;

import org.modeshape.common.CommonI18n;
import org.modeshape.common.logging.jdk.JdkLoggerFactory;
import org.modeshape.common.logging.log4j.Log4jLoggerFactory;
import org.modeshape.common.logging.slf4j.SLF4JLoggerFactory;
Expand Down Expand Up @@ -60,24 +61,51 @@ public abstract class LogFactory {
private static LogFactory LOGFACTORY;

static {
if (isSLF4JAvailable()) {
LOGFACTORY = new SLF4JLoggerFactory();
} else if (isLog4jAvailable()) {
LOGFACTORY = new Log4jLoggerFactory();
} else if (isCustomLoggerAvailable()) {
Throwable customLoggingError = null;
boolean customLogging = false;
boolean slf4jLogging = false;
boolean log4jLogging = false;

if (isCustomLoggerAvailable()) {
try {
@SuppressWarnings( "unchecked" )
Class<LogFactory> customClass = (Class<LogFactory>)Class.forName(CUSTOM_LOG_FACTORY_CLASSNAME);
LOGFACTORY = customClass.newInstance();
} catch (Throwable e) {
// We're going to fallback to the JDK logger anyway, so use it and log this problem ...
customLogging = true;
} catch (Throwable throwable) {
customLoggingError = throwable;
}
}

if (LOGFACTORY == null) {
if (isSLF4JAvailable()) {
LOGFACTORY = new SLF4JLoggerFactory();
slf4jLogging = true;
} else if (isLog4jAvailable()) {
LOGFACTORY = new Log4jLoggerFactory();
log4jLogging = true;
} else {
LOGFACTORY = new JdkLoggerFactory();
java.util.logging.Logger jdkLogger = java.util.logging.Logger.getLogger(LogFactory.class.getName());
String msg = org.modeshape.common.CommonI18n.errorInitializingCustomLoggerFactory.text(CUSTOM_LOG_FACTORY_CLASSNAME);
jdkLogger.log(java.util.logging.Level.WARNING, msg, e);
}
}

Logger logger = LOGFACTORY.getLogger(LogFactory.class.getName());

if (customLogging) {
logger.info(CommonI18n.customLoggingAvailable, CUSTOM_LOG_FACTORY_CLASSNAME);
} else if (slf4jLogging) {
logger.info(CommonI18n.slf4jAvailable);
} else if (log4jLogging) {
logger.info(CommonI18n.log4jAvailable);
} else {
LOGFACTORY = new JdkLoggerFactory();
logger.info(CommonI18n.jdkFallback);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hchiorean, why are these log messages output at INFO level? That seems excessive. (Just noticed it now.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these should be printed out only once per VM init, my thinking was that it would be useful to know which logging library is being used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps. Should the messages say something about ModeShape to give better context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can update the messages to reflect this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (customLoggingError != null) {
// log the problem related to the custom logger
logger.warn(customLoggingError,
CommonI18n.errorInitializingCustomLoggerFactory,
CUSTOM_LOG_FACTORY_CLASSNAME);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ componentConfigClasspathPropertyDescription = The names of the classpaths upon w
componentConfigClasspathPropertyLabel = Classpath names
componentConfigClasspathPropertyCategory =

errorInitializingCustomLoggerFactory = Error loading and/or instantiating the '{0}' implementation, which is used to tie ModeShape into a custom logging framework (other than SLF4J, Log4J or the JDK Logging). Falling back to JDK logging.
errorInitializingCustomLoggerFactory = Error loading and/or instantiating the '{0}' implementation, which is used to tie ModeShape into a custom logging framework (other than SLF4J, Log4J or the JDK Logging).
customLoggingAvailable = '{0}' located in the classpath; it will be used for logging
slf4jAvailable = SLF4J implementation located in the classpath; it will be used for logging
log4jAvailable = Log4j located in the classpath; it will be used for logging
jdkFallback = No custom logger, SLF4J implementation or Log4j located in the classpath. JDK logger will be used for logging