Search in sources :

Example 41 with ClassDefinition

use of lucee.runtime.db.ClassDefinition 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;
}
Also used : LoggerAndSourceData(lucee.commons.io.log.LoggerAndSourceData) Log(lucee.commons.io.log.Log) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) Entry(java.util.Map.Entry) Collection(lucee.runtime.type.Collection) Level(org.apache.log4j.Level) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Key(lucee.runtime.type.Collection.Key) Pair(lucee.commons.lang.Pair)

Aggregations

ClassDefinition (lucee.runtime.db.ClassDefinition)41 ClassDefinitionImpl (lucee.transformer.library.ClassDefinitionImpl)24 Element (org.w3c.dom.Element)15 ApplicationException (lucee.runtime.exp.ApplicationException)12 lucee.aprint (lucee.aprint)11 Struct (lucee.runtime.type.Struct)10 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)9 CPPCFXTagClass (lucee.runtime.cfx.customtag.CPPCFXTagClass)9 JavaCFXTagClass (lucee.runtime.cfx.customtag.JavaCFXTagClass)9 PageException (lucee.runtime.exp.PageException)9 BundleException (org.osgi.framework.BundleException)9 IOException (java.io.IOException)8 Map (java.util.Map)8 ClassException (lucee.commons.lang.ClassException)8 SecurityException (lucee.runtime.exp.SecurityException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 MalformedURLException (java.net.MalformedURLException)7 HashMap (java.util.HashMap)7 Entry (java.util.Map.Entry)7 StructImpl (lucee.runtime.type.StructImpl)7