use of lucee.runtime.engine.ExecutionLog in project Lucee by lucee.
the class XMLConfigWebFactory method loadExeLog.
private static void loadExeLog(ConfigServerImpl configServer, ConfigImpl config, Document doc) {
boolean hasServer = configServer != null;
Element el = getChildByName(doc.getDocumentElement(), "execution-log");
// enabled
Boolean bEnabled = Caster.toBoolean(getAttr(el, "enabled"), null);
if (bEnabled == null) {
if (hasServer)
config.setExecutionLogEnabled(configServer.getExecutionLogEnabled());
} else
config.setExecutionLogEnabled(bEnabled.booleanValue());
boolean hasChanged = false;
String val = Caster.toString(config.getExecutionLogEnabled());
try {
Resource contextDir = config.getConfigDir();
Resource exeLog = contextDir.getRealResource("exe-log");
if (!exeLog.exists()) {
exeLog.createNewFile();
IOUtil.write(exeLog, val, SystemUtil.getCharset(), false);
hasChanged = true;
} else if (!IOUtil.toString(exeLog, SystemUtil.getCharset()).equals(val)) {
IOUtil.write(exeLog, val, SystemUtil.getCharset(), false);
hasChanged = true;
}
} catch (IOException e) {
e.printStackTrace(config.getErrWriter());
}
if (hasChanged) {
try {
if (config.getClassDirectory().exists())
config.getClassDirectory().remove(true);
} catch (IOException e) {
e.printStackTrace(config.getErrWriter());
}
}
// class
String strClass = getAttr(el, "class");
Class clazz;
if (!StringUtil.isEmpty(strClass)) {
try {
if ("console".equalsIgnoreCase(strClass))
clazz = ConsoleExecutionLog.class;
else {
ClassDefinition cd = getClassDefinition(el, "", config.getIdentification());
Class c = cd.getClazz();
if ((c.newInstance() instanceof ExecutionLog)) {
clazz = c;
} else {
clazz = ConsoleExecutionLog.class;
SystemOut.printDate(config.getErrWriter(), "class [" + strClass + "] must implement the interface " + ExecutionLog.class.getName());
}
}
} catch (Exception e) {
SystemOut.printDate(e);
clazz = ConsoleExecutionLog.class;
}
if (clazz != null)
SystemOut.printDate(config.getOutWriter(), "loaded ExecutionLog class " + clazz.getName());
// arguments
String strArgs = getAttr(el, "arguments");
if (StringUtil.isEmpty(strArgs))
strArgs = getAttr(el, "class-arguments");
Map<String, String> args = toArguments(strArgs, true);
config.setExecutionLogFactory(new ExecutionLogFactory(clazz, args));
} else {
if (hasServer)
config.setExecutionLogFactory(configServer.getExecutionLogFactory());
else
config.setExecutionLogFactory(new ExecutionLogFactory(ConsoleExecutionLog.class, new HashMap<String, String>()));
}
}
Aggregations