Turning on Debug Logging

June 10th, 2021


Three easy steps to start debugging

Step 1

  • Open a terminal and navigate to the data folder for your Mango installation and download log4j2.xml.

Linux and Mac users:

cd MA_HOME
wget https://docs-v5.radixiot.com/assets/files/5.0.x/log4j2.xml

Windows users:

cd MA_HOME
curl https://docs-v5.radixiot.com/assets/files/5.0.x/log4j2.xml

Step 2

  • Open log4j2.xml and using the information below, insert the corresponding lines into the log4j2.xml configuration file in between the <Logger> <Logger /> tags.

Example:

<Loggers>
        <AsyncLogger name="com.infiniteautomation.tsdb.corruption" level="info" additivity="false">
          <AppenderRef ref="corruption"/>
        </AsyncLogger>
        <AsyncLogger name="com.infiniteautomation.tsdb.compression" level="info" additivity="false">
          <AppenderRef ref="compression"/>
        </AsyncLogger>
        <AsyncLogger name="com.infiniteautomation.tsdb.reverser" level="info" additivity="false">
          <AppenderRef ref="reverser"/>
        </AsyncLogger>
        <AsyncLogger name="script" includeLocation="${mango:logger.script.includeLocation}" level="${mango:logger.script.level}" additivity="false">
            <AppenderRef ref="script" level="${mango:appender.script.level}" />
        </AsyncLogger>
    &lt;AsyncLogger name=&quot;com.serotonin.m2m2&quot; includeLocation=&quot;${mango:logger.mango.includeLocation}&quot; level=&quot;${mango:logger.mango.level}&quot;/&gt;
    &lt;AsyncLogger name=&quot;com.infiniteautomation&quot; includeLocation=&quot;${mango:logger.mango.includeLocation}&quot; level=&quot;${mango:logger.mango.level}&quot;/&gt;
    &lt;AsyncRoot includeLocation=&quot;${mango:logger.root.includeLocation}&quot; level=&quot;${mango:logger.root.level}&quot;&gt;
        &lt;AppenderRef ref=&quot;logfile&quot; level=&quot;${mango:appender.logfile.level}&quot; /&gt;
        &lt;AppenderRef ref=&quot;stdout&quot; level=&quot;${mango:appender.stdout.level}&quot; /&gt;
    &lt;/AsyncRoot&gt;
&lt;/Loggers&gt;

BACnet

Log4J2

<AsyncLogger includeLocation="true" name="com.serotonin.bacnet4j" level="debug"/>
<AsyncLogger includeLocation="true" name="com.serotonin.ma.bacnet" level="debug"/>

SNMP

Log4J2

<AsyncLogger includeLocation=”true” name="com.serotonin.m2m2.snmp" level="debug"/>
<AsyncLogger includeLocation=”true” name="org.snmp4j" level="debug"/>

Turn off poll aborted logs

<AsyncLogger includeLocation=”true”  name="com.serotonin.m2m2.rt.dataSource.PollingDataSource" level="error"/>

HAYSTACK

<AsyncLogger includeLocation="true" name="com.infiniteautomation.mango.haystack" level="debug"/>
<AsyncLogger includeLocation="true" name="org.projecthaystack" level="debug"/>

AsyncLogger Parameters

Log4j Level Description
trace Finest grain logging, Mango has little of this although some of its libraries may use it.
debug For debugging problems, will fill up logs quickly for best results try to use the closest category to where your problem is when using this level.
info Default Logging Level for most of Mango
warn Capture Warning information
error Capture Errors
fatal Capture only disastrous level events.
Log4j Category Name Description
com.serotonin.m2m2 All Serotonin Code for Mango
com.infiniteautomation.mango All IA Code for Mango
com.serotonin.m2m2.db Mango Database Code
com.serotonin.m2m2.email Mango Email Code
com.serotonin.m2m2.i18n Mango Translations
com.serotonin.m2m2.rt Mango Realtime Code (Data source,event detectors etc)
com.serotonin.m2m2.web.mvc.rest Mango REST Code
com.serotonin.m2m2.rt.event Event Detectors
com.serotonin.m2m2.rt.maint Backups and Purges
com.serotonin.m2m2.rt.dataSource Core Data Source code
com.serotonin.m2m2.rt.publish Core Publisher code
com.serotonin.m2m2.rt.script Core Java Scripting Code
com.serotonin.ma.bacnet BACnet Module
com.serotonin.bacnet4j BACnet Protocol
com.serotonin.m2m2.snmp SNMP Module
org.snmp4j SNMP Protocol
com.infiniteautomation.brewersdashboard.rt Brewers Dashboard DS and Alarms

Step 3

  • Open env.properties file and set log4j2.configurationFile=log4j2.xml. The path is relative to your data directory, paths.data, you may also provide an absolute path if you desire.

Additional Notes

  • You can reference Mango env.properties in the log4j2.xml file using the syntax ${mango:env.property.key} as seen below:
<?xml version="1.0" encoding="UTF-8" ?>
<!--
  ~ Copyright (C) 2020 Radix IoT LLC. All rights reserved.
  -->
<Configuration packages="com.serotonin.m2m2.rt.console">
    <Appenders>
        <Console name="stdout" target="SYSTEM_OUT">
            <PatternLayout pattern="${mango:appender.stdout.pattern}"/>
        </Console>
        <RollingRandomAccessFile name="logfile" filePattern="${mango:paths.logs}/%d{MM-dd-yyyy}-%i.ma.log.gz" fileName="${mango:paths.logs}/ma.log">
            <PatternLayout pattern="${mango:appender.logfile.pattern}"/>
            <Policies>
                <OnStartupTriggeringPolicy />
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="${mango:appender.logfile.size}"/>
            </Policies>
            <DefaultRolloverStrategy fileIndex="nomax">
                <Delete basePath="${mango:paths.logs}" >
                    <IfFileName glob="*.ma.{log,log.gz}" />
                    <IfAny>
                        <IfLastModified age="${mango:appender.logfile.delete.age}" />
                        <IfAccumulatedFileSize exceeds="${mango:appender.logfile.delete.size}" />
                        <IfAccumulatedFileCount exceeds="${mango:appender.logfile.delete.count}" />
                    </IfAny>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
        <!-- IasTsdb Logging -->
        <RollingRandomAccessFile name="corruption" filePattern="${mango:paths.logs}/%d{MM-dd-yyyy}-%i.iastsdb-corruption.log.gz" fileName="${mango:paths.logs}/iastsdb-corruption.log">
            <PatternLayout pattern="%m"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="5MB"/>
            </Policies>
            <DefaultRolloverStrategy fileIndex="nomax">
                <Delete basePath="${mango:paths.logs}" >
                    <IfFileName glob="*.iastsdb-corruption.{log,log.gz}" />
                    <IfAccumulatedFileCount exceeds="20"/>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile name="compression" filePattern="${mango:paths.logs}/%d{MM-dd-yyyy}-%i.iastsdb-compression.log.gz" fileName="${mango:paths.logs}/iastsdb-compression.log">
            <PatternLayout pattern="%m"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="5MB"/>
            </Policies>
            <DefaultRolloverStrategy fileIndex="nomax">
                <Delete basePath="${mango:paths.logs}" >
                    <IfFileName glob="*.iastsdb-compression.{log,log.gz}" />
                    <IfAccumulatedFileCount exceeds="20"/>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile name="reverser" filePattern="${mango:paths.logs}/%d{MM-dd-yyyy}-%i.iastsdb-reverse.log.gz" fileName="${mango:paths.logs}/iastsdb-reverse.log">
            <PatternLayout pattern="%m"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="5MB"/>
            </Policies>
            <DefaultRolloverStrategy fileIndex="nomax">
                <Delete basePath="logs" >
                    <IfFileName glob="*.iastsdb-reverse.{log,log.gz}" />
                    <IfAccumulatedFileCount exceeds="20"/>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile name="script" filePattern="${mango:paths.logs}/%d{MM-dd-yyyy}-%i.script.log.gz" fileName="${mango:paths.logs}/script.log">
            <PatternLayout pattern="${mango:appender.script.pattern}"/>
            <Policies>
                <OnStartupTriggeringPolicy />
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="${mango:appender.script.size}"/>
            </Policies>
            <DefaultRolloverStrategy fileIndex="nomax">
                <Delete basePath="${mango:paths.logs}" >
                    <IfFileName glob="*.script.{log,log.gz}" />
                    <IfAny>
                        <IfLastModified age="${mango:appender.script.delete.age}" />
                        <IfAccumulatedFileSize exceeds="${mango:appender.script.delete.size}" />
                        <IfAccumulatedFileCount exceeds="${mango:appender.script.delete.count}" />
                    </IfAny>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <AsyncLogger name="com.infiniteautomation.tsdb.corruption" level="info" additivity="false">
          <AppenderRef ref="corruption"/>
        </AsyncLogger>
        <AsyncLogger name="com.infiniteautomation.tsdb.compression" level="info" additivity="false">
          <AppenderRef ref="compression"/>
        </AsyncLogger>
        <AsyncLogger name="com.infiniteautomation.tsdb.reverser" level="info" additivity="false">
          <AppenderRef ref="reverser"/>
        </AsyncLogger>
        <AsyncLogger name="script" includeLocation="${mango:logger.script.includeLocation}" level="${mango:logger.script.level}" additivity="false">
            <AppenderRef ref="script" level="${mango:appender.script.level}" />
        </AsyncLogger>

        <AsyncLogger name="com.serotonin.m2m2" includeLocation="${mango:logger.mango.includeLocation}" level="${mango:logger.mango.level}"/>         <AsyncLogger name="com.infiniteautomation" includeLocation="${mango:logger.mango.includeLocation}" level="${mango:logger.mango.level}"/>         <AsyncRoot includeLocation="${mango:logger.root.includeLocation}" level="${mango:logger.root.level}">             <AppenderRef ref="logfile" level="${mango:appender.logfile.level}" />             <AppenderRef ref="stdout" level="${mango:appender.stdout.level}" />         </AsyncRoot>     </Loggers> </Configuration>

Common Issues

  • The log4j2.xml file is in the wrong directory. To find out where to put the file, open env.properties and find the paths.data= entry. If this is empty, the path is relative to paths.home in the same file. If this is also empty, the directory you need to place the log4j12.xml file in is the root directory of your Mango installation, also known as MA_HOME.

Copyright © 2024 Radix IoT, LLC.