Skip to main content
Support

KB Article #181723

Traces in Scripting Language Filters are Indented

Problem

Traces made by calling com.vordel.trace.Trace in Scripting Language filters are indented, whereas traces from a Trace filter are not. This may cause strangely indented traces if you write traces at INFO or higher levels and do not see the surrounding filter context at DEBUG showing why they are indented to match.

Resolution

It is possible to set the indentation level to zero in your code. That said, please note that you must also restore the prior indentation level when you are done, because the Scripting Language filter will call Trace.indentLeave() to lower the indentation level by one after your script exits and this will cause an error saying "trace indentation botch: further trace will not be indented" if the indentation level is zero when that is called, because an indentation level of -1 is not possible. The following JavaScript sample demonstrates how one might write traces from a script without having them be indented by the surrounding context:


        prior_indent = Trace.getIndent();
        while (Trace.getIndent() > 0) {
                Trace.indentLeave();
        }

        Trace.info("Indent is now zero: " + Trace.getIndent());
        Trace.info("Restoring indentation");

        while (Trace.getIndent() < prior_indent) {
                Trace.indentEnter();
        }


The function Trace.getIndent() returns an integer specifying the indentation level, while Trace.indentEnter() increases the indentation level by one and Trace.indentLeave() decreases the indentation level by one if doing so does not result in a negative value. There is no method to set a particular indentation level directly.