Search in sources :

Example 1 with DebugTrace

use of lucee.runtime.debug.DebugTrace in project Lucee by lucee.

the class Trace method _doEndTag.

public void _doEndTag() throws IOException, PageException {
    PageSource ps = pageContext.getCurrentTemplatePageSource();
    // var
    String varValue = null;
    Object value = null, traceValue = null;
    if (!StringUtil.isEmpty(var)) {
        try {
            if (caller instanceof Scope)
                value = VariableInterpreter.getVariable(pageContext, var, (Scope) caller);
            else
                value = pageContext.getVariable(var);
        } catch (PageException e) {
            varValue = "(undefined)";
            follow = false;
        }
        if (follow) {
            // print.o(1);
            if (StringUtil.isEmpty(text, true))
                text = var;
            // print.o(2);
            traceValue = TraceObjectSupport.toTraceObject(pageContext.getDebugger(), value, type, category, text);
            if (caller instanceof Scope)
                VariableInterpreter.setVariable(pageContext, var, traceValue, (Scope) caller);
            else
                pageContext.setVariable(var, traceValue);
        }
        try {
            varValue = new ScriptConverter().serialize(value);
        } catch (ConverterException e) {
            if (value != null)
                varValue = "(" + Caster.toTypeName(value) + ")";
        }
    }
    DebugTrace trace = ((DebuggerImpl) pageContext.getDebugger()).addTrace(type, category, text, ps, var, varValue);
    DebugTrace[] traces = pageContext.getDebugger().getTraces(pageContext);
    String total = "(1st trace)";
    if (traces.length > 1) {
        long t = 0;
        for (int i = 0; i < traces.length; i++) {
            t += traces[i].getTime();
        }
        total = "(" + t + ")";
    }
    boolean hasCat = !StringUtil.isEmpty(trace.getCategory());
    boolean hasText = !StringUtil.isEmpty(trace.getText());
    boolean hasVar = !StringUtil.isEmpty(var);
    // inline
    if (inline) {
        lucee.runtime.format.TimeFormat tf = new lucee.runtime.format.TimeFormat(pageContext.getConfig().getLocale());
        StringBuffer sb = new StringBuffer();
        sb.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"white\">");
        sb.append("<tr>");
        // sb.append("<td><img src=\"/CFIDE/debug/images/Error_16x16.gif\" alt=\"Error type\">");
        sb.append("<td>");
        sb.append("<font color=\"orange\">");
        sb.append("<b>");
        sb.append(DebugTraceImpl.toType(trace.getType(), "INFO") + " - ");
        sb.append("[CFTRACE " + tf.format(new DateTimeImpl(pageContext.getConfig()), "hh:mm:ss:l") + "]");
        sb.append("[" + trace.getTime() + " ms " + total + "]");
        sb.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
        if (hasCat || hasText)
            sb.append(" -");
        if (hasCat)
            sb.append("  [" + trace.getCategory() + "]");
        if (hasText)
            sb.append(" <i>" + trace.getText() + "&nbsp;</i>");
        sb.append("</b>");
        sb.append("</font>");
        sb.append("</td>");
        sb.append("</tr>");
        sb.append("</table>");
        pageContext.forceWrite(sb.toString());
        if (hasVar)
            Dump.call(pageContext, value, var);
    }
    // log
    Log log = ((ConfigImpl) pageContext.getConfig()).getLog("trace");
    StringBuffer msg = new StringBuffer();
    msg.append("[" + trace.getTime() + " ms " + total + "] ");
    msg.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
    if (hasCat || hasText || hasVar)
        msg.append("- ");
    if (hasCat)
        msg.append("[" + trace.getCategory() + "] ");
    if (hasVar)
        msg.append("[" + var + "=" + varValue + "] ");
    if (hasText)
        msg.append(" " + trace.getText() + " ");
    log.log(trace.getType(), "cftrace", msg.toString());
    // abort
    if (abort)
        throw new Abort(Abort.SCOPE_REQUEST);
}
Also used : PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) Log(lucee.commons.io.log.Log) DebuggerImpl(lucee.runtime.debug.DebuggerImpl) PageSource(lucee.runtime.PageSource) Abort(lucee.runtime.exp.Abort) Scope(lucee.runtime.type.scope.Scope) DebugTrace(lucee.runtime.debug.DebugTrace) ScriptConverter(lucee.runtime.converter.ScriptConverter) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Aggregations

Log (lucee.commons.io.log.Log)1 PageSource (lucee.runtime.PageSource)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 ConverterException (lucee.runtime.converter.ConverterException)1 ScriptConverter (lucee.runtime.converter.ScriptConverter)1 DebugTrace (lucee.runtime.debug.DebugTrace)1 DebuggerImpl (lucee.runtime.debug.DebuggerImpl)1 Abort (lucee.runtime.exp.Abort)1 PageException (lucee.runtime.exp.PageException)1 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)1 Scope (lucee.runtime.type.scope.Scope)1