6 changed files with 157 additions and 3 deletions
@ -0,0 +1,114 @@
|
||||
package org.leolo.nrdatad; |
||||
|
||||
import org.apache.logging.log4j.LogManager; |
||||
import org.apache.logging.log4j.Logger; |
||||
|
||||
import java.io.FileReader; |
||||
import java.io.IOException; |
||||
import java.io.PrintStream; |
||||
import java.io.PrintWriter; |
||||
import java.util.*; |
||||
import java.util.function.BiConsumer; |
||||
|
||||
public final class ConfigurationManager { |
||||
private static ConfigurationManager instance; |
||||
Logger logger = LogManager.getLogger(); |
||||
Properties prop = new Properties(); |
||||
|
||||
public synchronized static ConfigurationManager getInstance(){ |
||||
if(instance==null){ |
||||
instance = new ConfigurationManager(); |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
private ConfigurationManager(){ |
||||
|
||||
} |
||||
|
||||
public void loadConfiguration(String configPath) { |
||||
logger.atInfo().log("Loading configuration file {}.", configPath); |
||||
try { |
||||
prop.load(new FileReader(configPath)); |
||||
} catch (IOException e) { |
||||
logger.atError().withThrowable(e).log("Unable to load configuration file"); |
||||
} |
||||
logger.atInfo().log("Loaded {} setting(s)", prop.size()); |
||||
} |
||||
|
||||
public Object setProperty(String key, String value) { |
||||
return prop.setProperty(key, value); |
||||
} |
||||
|
||||
public String getProperty(String key) { |
||||
return prop.getProperty(key); |
||||
} |
||||
|
||||
public String getProperty(String key, String defaultValue) { |
||||
return prop.getProperty(key, defaultValue); |
||||
} |
||||
|
||||
public Enumeration<?> propertyNames() { |
||||
return prop.propertyNames(); |
||||
} |
||||
|
||||
public Set<String> stringPropertyNames() { |
||||
return prop.stringPropertyNames(); |
||||
} |
||||
|
||||
public void list(PrintStream out) { |
||||
prop.list(out); |
||||
} |
||||
|
||||
public void list(PrintWriter out) { |
||||
prop.list(out); |
||||
} |
||||
|
||||
public int size() { |
||||
return prop.size(); |
||||
} |
||||
|
||||
public boolean isEmpty() { |
||||
return prop.isEmpty(); |
||||
} |
||||
|
||||
public Enumeration<Object> keys() { |
||||
return prop.keys(); |
||||
} |
||||
|
||||
public Enumeration<Object> elements() { |
||||
return prop.elements(); |
||||
} |
||||
|
||||
public boolean contains(Object value) { |
||||
return prop.contains(value); |
||||
} |
||||
|
||||
public boolean containsValue(Object value) { |
||||
return prop.containsValue(value); |
||||
} |
||||
|
||||
public boolean containsKey(Object key) { |
||||
return prop.containsKey(key); |
||||
} |
||||
|
||||
public Set<Object> keySet() { |
||||
return prop.keySet(); |
||||
} |
||||
|
||||
public Collection<Object> values() { |
||||
return prop.values(); |
||||
} |
||||
|
||||
public Set<Map.Entry<Object, Object>> entrySet() { |
||||
return prop.entrySet(); |
||||
} |
||||
|
||||
public Object getOrDefault(Object key, Object defaultValue) { |
||||
return prop.getOrDefault(key, defaultValue); |
||||
} |
||||
|
||||
public void forEach(BiConsumer<? super Object, ? super Object> action) { |
||||
prop.forEach(action); |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<Configuration status="warn"> |
||||
<Appenders> |
||||
<Console name="Console" target="SYSTEM_OUT"> |
||||
<PatternLayout |
||||
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> |
||||
</Console> |
||||
<File name="RIlog" fileName="ri_log"> |
||||
<PatternLayout |
||||
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> |
||||
</File> |
||||
</Appenders> |
||||
<Loggers> |
||||
<Root level="info"> |
||||
<AppenderRef ref="Console" /> |
||||
</Root> |
||||
<Logger name="org.leolo.nrdd"> |
||||
<AppenderRef ref="Console" /> |
||||
<AppenderRef ref="RIlog" /> |
||||
</Logger> |
||||
</Loggers> |
||||
</Configuration> |
||||
Loading…
Reference in new issue