Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/logger factory #3389

Merged
merged 7 commits into from
Jan 31, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
polishing code using map.computeIfAbsent
  • Loading branch information
kezhenxu94 committed Jan 30, 2019
commit e1a540bdf9dc10d2390e3835064d24b23079d9ff
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.dubbo.common.logger.jcl.JclLoggerAdapter;
import org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter;
import org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter;
import org.apache.dubbo.common.logger.log4j2.Log4j2Logger;
import org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter;
import org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter;
import org.apache.dubbo.common.logger.support.FailsafeLogger;
Expand All @@ -37,7 +36,7 @@
*/
public class LoggerFactory {

private static final ConcurrentMap<String, FailsafeLogger> LOGGERS = new ConcurrentHashMap<String, FailsafeLogger>();
private static final ConcurrentMap<String, FailsafeLogger> LOGGERS = new ConcurrentHashMap<>();
private static volatile LoggerAdapter LOGGER_ADAPTER;

// search common-used logging frameworks
Expand Down Expand Up @@ -109,12 +108,7 @@ public static void setLoggerAdapter(LoggerAdapter loggerAdapter) {
* @return logger
*/
public static Logger getLogger(Class<?> key) {
FailsafeLogger logger = LOGGERS.get(key.getName());
if (logger == null) {
LOGGERS.putIfAbsent(key.getName(), new FailsafeLogger(LOGGER_ADAPTER.getLogger(key)));
logger = LOGGERS.get(key.getName());
}
return logger;
return LOGGERS.computeIfAbsent(key.getName(), name -> new FailsafeLogger(LOGGER_ADAPTER.getLogger(key)));
kezhenxu94 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -124,12 +118,7 @@ public static Logger getLogger(Class<?> key) {
* @return logger provider
*/
public static Logger getLogger(String key) {
FailsafeLogger logger = LOGGERS.get(key);
if (logger == null) {
LOGGERS.putIfAbsent(key, new FailsafeLogger(LOGGER_ADAPTER.getLogger(key)));
logger = LOGGERS.get(key);
}
return logger;
return LOGGERS.computeIfAbsent(key, k -> new FailsafeLogger(LOGGER_ADAPTER.getLogger(k)));
}

/**
Expand Down