[X++] setPrefix explanation and use


setPrefix is a function to create headings in an infolog. It helps to identify the scope tho which the message belongs to and should be used whenever it makes sence.


setPrefix(str prefix)

The parameter is a string value representing the text you want to set as heading.
You can get more details here on MSDN.



The prefix depends on the scope your code is in. setPrefix adds the prefix for the current execution scope. When leaving the scope the prefix is automatically reset to the previous level. To retrieve the current execution prefix you can use getPrefix().

Root element

The infolog has a root element. If you don't call setPrefix it contains something like Message (10:23:29).
(This comes from classmethod info.newHeadLine.)
The first call to setPrefix will change this root element. So be sure to initial call setPrefix when you want to set more than one prefix in your process.


static void prefixExample(Args _args)
    void output1()
        info("This text is in output1");
        info("Scope is output1");

    void output2()
        info("This text is in output2");
        info("Scope is output2");

    // Important to set this!
    // You can only have 1 root prefix and if you don't set it, all calls to setprefix will belong to this root element.
    // Then only the first call will take effect.
    // Test it by commenting out the next line.
    setPrefix("Main Heading");


Result without the inital call: