com.github.marschall.slf4j.equinox.EquinoxLoggerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.github.marschall.slf4j-equinox Show documentation
Show all versions of com.github.marschall.slf4j-equinox Show documentation
An SLF4J implementation using the Equinox ExtendedLogService.
The newest version!
package com.github.marschall.slf4j.equinox;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.eclipse.equinox.log.ExtendedLogService;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
/**
* Log4jLoggerFactory is an implementation of {@link ILoggerFactory} returning
* the appropriate named {@link Log4jLoggerAdapter} instance.
*
* @author Philippe Marschall
*/
final class EquinoxLoggerFactory implements ILoggerFactory {
// TODO use weak values? ExtendedLogServiceImpl doesn't use weak values as well
// TODO synchronized instead of ConcurrentMap? ExtendedLogServiceImpl is synchronized as well
// TODO remove BasicReadWriteLock from Equinox
private final ConcurrentMap loggerMap;
private final ExtendedLogService logService;
EquinoxLoggerFactory() {
this.logService = EquinoxSLF4JBundleActivator.getDefaultInstance().getExtendedLogService();
this.loggerMap = new ConcurrentHashMap<>();
}
@Override
public Logger getLogger(String name) {
return this.loggerMap.computeIfAbsent(name, n -> {
org.eclipse.equinox.log.Logger equinoxLogger = this.logService.getLogger(n);
return new EquinoxLoggerAdapter(name, equinoxLogger);
});
}
}