mirror of https://github.com/qos-ch/slf4j
Use computeIfAbsent with a protected method, make reset protected
Signed-off-by: Guillaume Nodet <gnodet@gmail.com>
This commit is contained in:
parent
31a3a8d1f3
commit
1915ef81ca
|
|
@ -47,16 +47,19 @@ public class SimpleLoggerFactory implements ILoggerFactory {
|
|||
|
||||
/**
|
||||
* Return an appropriate {@link SimpleLogger} instance by name.
|
||||
*
|
||||
* This method will call {@link #createLogger(String)} if the logger
|
||||
* has not been created yet.
|
||||
*/
|
||||
public Logger getLogger(String name) {
|
||||
Logger simpleLogger = loggerMap.get(name);
|
||||
if (simpleLogger != null) {
|
||||
return simpleLogger;
|
||||
} else {
|
||||
Logger newInstance = new SimpleLogger(name);
|
||||
Logger oldInstance = loggerMap.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
}
|
||||
return loggerMap.computeIfAbsent(name, this::createLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually creates the logger for the given name.
|
||||
*/
|
||||
protected Logger createLogger(String name) {
|
||||
return new SimpleLogger(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,7 +71,7 @@ public class SimpleLoggerFactory implements ILoggerFactory {
|
|||
*
|
||||
* You are strongly discouraged from calling this method in production code.
|
||||
*/
|
||||
void reset() {
|
||||
protected void reset() {
|
||||
loggerMap.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue