Logging viper examples

This example first uses the viper logging.enabled() to determine if logging has been enabled. If that's the case, various types of messages are written to the log.

The first parameter for these vipers is the message to be written to the log. The second (required) parameter is the log category.

You can use any name you like as category, however depending on the configured logging filters and levels, your log message may or may not be actually written to the log.

The third (optional) parameter specifies the log level (1 through 10). It defaults to 1.

The second example block first disables logging, so the first log message will not be written. Then it (re-)enables logging, so the second information message will be written.

The ability to enable/disable logging on demand can be useful in scenarios where you want to trace messages and errors for a specific item or for a specific piece of sxml. Use with caution however, enabling/disabling logging has global impact, so logging.enable(false) will actually switch off logging permanently (for the complete site, until it is switched on again or the site is restarted).

Smartsite SXML CopyCode image Copy Code
<se:if expression="logging.enabled()">
    {logging.addcritical("critical message", "mycategory", 1)}
    {logging.adderror("error message", "mycategory", 1)}
    {logging.addwarning("warning message", "mycategory", 6)}
    {logging.addinformation("information message", "mycategory",4)}
    {logging.addtrace("trace message","mycategory", 2)}
    {logging.addverbose("verbose message", "mycategory")}
</se:if>

{logging.enable(false)}
{logging.addinformation("this message will not be written to the log", "mycategory")}
{logging.enable(true)}
{logging.addinformation("this message will be written to the log", "mycategory")}