![JAR search and dependency download from the Maven repository](/logo.png)
panda.log.impl.AbstractLogAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.log.impl;
import java.util.Map;
import java.util.Map.Entry;
import panda.log.Log;
import panda.log.LogAdapter;
import panda.log.LogFormat;
import panda.log.LogFormat.SimpleLogFormat;
import panda.log.LogLevel;
import panda.log.Logs;
public abstract class AbstractLogAdapter implements LogAdapter {
/** logs */
protected Logs logs;
/** adapter name */
protected String name;
protected LogLevel threshold;
protected LogFormat format = LogFormat.DEFAULT;
@Override
public void init(Logs logs, String name, Map props) {
this.logs = logs;
this.name = name;
String prefix = "logger." + name + ".";
setProperties(prefix, props);
}
@Override
public Log getLog(String name) {
if (logs.isLoggerEnabled(this.name, name)) {
return getLogger(name);
}
return NopLog.INSTANCE;
}
protected abstract Log getLogger(String name);
protected void setProperties(String prefix, Map props) {
for (Entry en : props.entrySet()) {
String key = en.getKey();
if (key.startsWith(prefix)) {
key = key.substring(prefix.length());
setProperty(key, en.getValue());
}
}
}
protected void setProperty(String name, String value) {
if ("threshold".equalsIgnoreCase(name)) {
setThreshold(value);
}
else if ("format".equalsIgnoreCase(name)) {
setFormat(value);
}
}
protected void setThreshold(String threshold) {
this.threshold = LogLevel.parse(threshold);
}
protected void setFormat(String pattern) {
this.format = new SimpleLogFormat(pattern);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy