use of lucee.commons.io.log.LoggerAndSourceData in project Lucee by lucee.
the class Admin method _doGetLogSettings.
private Query _doGetLogSettings() {
Map<String, LoggerAndSourceData> loggers = config.getLoggers();
Query qry = new QueryImpl(new String[] { "name", "level", "appenderClass", "appenderBundleName", "appenderBundleVersion", "appenderArgs", "layoutClass", "layoutBundleName", "layoutBundleVersion", "layoutArgs", "readonly" }, 0, lucee.runtime.type.util.ListUtil.last("logs", '.'));
int row = 0;
Iterator<Entry<String, LoggerAndSourceData>> it = loggers.entrySet().iterator();
Entry<String, LoggerAndSourceData> e;
LoggerAndSourceData logger;
while (it.hasNext()) {
e = it.next();
logger = e.getValue();
if (logger.getDyn())
continue;
row = qry.addRow();
// row++;
qry.setAtEL("name", row, e.getKey());
qry.setAtEL("level", row, logger.getLevel().toString());
qry.setAtEL("appenderClass", row, logger.getAppenderClassDefinition().getClassName());
qry.setAtEL("appenderBundleName", row, logger.getAppenderClassDefinition().getName());
qry.setAtEL("appenderBundleVersion", row, logger.getAppenderClassDefinition().getVersionAsString());
qry.setAtEL("appenderArgs", row, toStruct(logger.getAppenderArgs()));
qry.setAtEL("layoutClass", row, logger.getLayoutClassDefinition().getClassName());
qry.setAtEL("layoutBundleName", row, logger.getLayoutClassDefinition().getName());
qry.setAtEL("layoutBundleVersion", row, logger.getLayoutClassDefinition().getVersionAsString());
qry.setAtEL("layoutArgs", row, toStruct(logger.getLayoutArgs()));
qry.setAtEL("readonly", row, logger.getReadOnly());
}
return qry;
}
use of lucee.commons.io.log.LoggerAndSourceData in project Lucee by lucee.
the class XMLConfigWebFactory method loadLoggers.
private static void loadLoggers(ConfigServerImpl configServer, ConfigImpl config, Document doc, boolean isReload) {
config.clearLoggers(Boolean.FALSE);
Element parent = getChildByName(doc.getDocumentElement(), "logging");
Element[] children = getChildren(parent, "logger");
Element child;
String name, appenderArgs, tmp, layoutArgs;
ClassDefinition cdAppender, cdLayout;
Level level = Level.ERROR;
boolean readOnly = false;
for (int i = 0; i < children.length; i++) {
child = children[i];
name = StringUtil.trim(getAttr(child, "name"), "");
// appender
cdAppender = getClassDefinition(child, "appender-", config.getIdentification());
if (!cdAppender.hasClass()) {
tmp = StringUtil.trim(getAttr(child, "appender"), "");
cdAppender = Log4jUtil.appenderClassDefintion(tmp);
}
appenderArgs = StringUtil.trim(getAttr(child, "appender-arguments"), "");
// layout
cdLayout = getClassDefinition(child, "layout-", config.getIdentification());
if (!cdLayout.hasClass()) {
tmp = StringUtil.trim(getAttr(child, "layout"), "");
cdLayout = Log4jUtil.layoutClassDefintion(tmp);
}
layoutArgs = StringUtil.trim(getAttr(child, "layout-arguments"), "");
String strLevel = getAttr(child, "level");
if (StringUtil.isEmpty(strLevel, true))
strLevel = getAttr(child, "log-level");
level = Log4jUtil.toLevel(StringUtil.trim(strLevel, ""), Level.ERROR);
readOnly = Caster.toBooleanValue(getAttr(child, "read-only"), false);
// ignore when no appender/name is defined
if (cdAppender.hasClass() && !StringUtil.isEmpty(name)) {
Map<String, String> appArgs = cssStringToMap(appenderArgs, true, true);
if (cdLayout.hasClass()) {
Map<String, String> layArgs = cssStringToMap(layoutArgs, true, true);
config.addLogger(name, level, cdAppender, appArgs, cdLayout, layArgs, readOnly, false);
} else
config.addLogger(name, level, cdAppender, appArgs, null, null, readOnly, false);
}
}
if (configServer != null) {
Iterator<Entry<String, LoggerAndSourceData>> it = configServer.getLoggers().entrySet().iterator();
Entry<String, LoggerAndSourceData> e;
LoggerAndSourceData data;
while (it.hasNext()) {
e = it.next();
// logger only exists in server context
if (config.getLog(e.getKey(), false) == null) {
data = e.getValue();
config.addLogger(e.getKey(), data.getLevel(), data.getAppenderClassDefinition(), data.getAppenderArgs(), data.getLayoutClassDefinition(), data.getLayoutArgs(), true, false);
}
}
}
}
use of lucee.commons.io.log.LoggerAndSourceData in project Lucee by lucee.
the class ApplicationContextSupport method addLogger.
private static LoggerAndSourceData addLogger(Collection.Key name, Level level, ClassDefinition appender, Map<String, String> appenderArgs, ClassDefinition layout, Map<String, String> layoutArgs, boolean readOnly) {
LoggerAndSourceData existing = _loggers.get(name);
String id = LoggerAndSourceData.id(name.getLowerString(), appender, appenderArgs, layout, layoutArgs, level, readOnly);
if (existing != null) {
if (existing.id().equals(id)) {
return existing;
}
existing.close();
}
LoggerAndSourceData las = new LoggerAndSourceData(null, id, name.getLowerString(), appender, appenderArgs, layout, layoutArgs, level, readOnly, true);
_loggers.put(name, las);
return las;
}
use of lucee.commons.io.log.LoggerAndSourceData in project Lucee by lucee.
the class ConfigImpl method addLogger.
protected LoggerAndSourceData addLogger(String name, Level level, ClassDefinition appender, Map<String, String> appenderArgs, ClassDefinition layout, Map<String, String> layoutArgs, boolean readOnly, boolean dyn) {
LoggerAndSourceData existing = loggers.get(name.toLowerCase());
String id = LoggerAndSourceData.id(name.toLowerCase(), appender, appenderArgs, layout, layoutArgs, level, readOnly);
if (existing != null) {
if (existing.id().equals(id)) {
return existing;
}
existing.close();
}
LoggerAndSourceData las = new LoggerAndSourceData(this, id, name.toLowerCase(), appender, appenderArgs, layout, layoutArgs, level, readOnly, dyn);
loggers.put(name.toLowerCase(), las);
return las;
}
use of lucee.commons.io.log.LoggerAndSourceData in project Lucee by lucee.
the class ApplicationContextSupport method initLog.
public static Map<Collection.Key, Pair<Log, Struct>> initLog(Struct sct) {
Map<Collection.Key, Pair<Log, Struct>> rtn = new ConcurrentHashMap<Collection.Key, Pair<Log, Struct>>();
if (sct == null)
return rtn;
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
Struct v;
int k;
Collection.Key name;
LoggerAndSourceData las;
while (it.hasNext()) {
e = it.next();
name = e.getKey();
v = Caster.toStruct(e.getValue(), null);
if (v == null)
continue;
// raw way
Struct sctApp = Caster.toStruct(v.get("appender", null), null);
ClassDefinition cdApp = toClassDefinition(sctApp, null, true, false);
Struct sctLay = Caster.toStruct(v.get("layout", null), null);
ClassDefinition cdLay = toClassDefinition(sctLay, null, false, true);
if (cdApp != null && cdApp.hasClass()) {
// level
String strLevel = Caster.toString(v.get("level", null), null);
if (StringUtil.isEmpty(strLevel, true))
Caster.toString(v.get("loglevel", null), null);
Level level = Log4jUtil.toLevel(StringUtil.trim(strLevel, ""), Level.ERROR);
Struct sctAppArgs = Caster.toStruct(sctApp.get("arguments", null), null);
Struct sctLayArgs = Caster.toStruct(sctLay.get("arguments", null), null);
boolean readOnly = Caster.toBooleanValue(v.get("readonly", null), false);
// ignore when no appender/name is defined
if (!StringUtil.isEmpty(name)) {
Map<String, String> appArgs = toMap(sctAppArgs);
if (cdLay != null && cdLay.hasClass()) {
Map<String, String> layArgs = toMap(sctLayArgs);
las = addLogger(name, level, cdApp, appArgs, cdLay, layArgs, readOnly);
} else
las = addLogger(name, level, cdApp, appArgs, null, null, readOnly);
rtn.put(name, new Pair<Log, Struct>(las.getLog(), v));
}
}
}
return rtn;
}
Aggregations