Logging from data file importers
-
Hey, I'm sorry if this this a newbie question but I don't have a terribly huge amount of experience with coding in Java/Mango. I'd like to enable some verbose logging from my data file source importers, what's the best way to do such a thing? I'l like to be able to dump the contents of the memory so I can "see what it sees" as it parses a CSV for me.
Thanks all
-
Hi psysak, tis a great question!
You can import and create a logger in the data file class if you want that output in the ma.log file, or you can call
System.out.println("This is some output!");
to print that to the console (wouldn't be in the log file). Or, you could open a FileOutputStream and write your log to its own file.If you want to use the logger, you'll need to import...
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
and as a class member variable (inside the class definition):
public class YourImporterClassname { //class definition private final Log LOG = LogFactory.getLog(YourImporterClassname.class); ... //Rest of class
and then you'll be able to call these throughout your class,
LOG.fatal("FATAL!"); LOG.error("ERROR!"); LOG.warn("WARN!"); LOG.info("INFO!"); LOG.trace("TRACE!");
And see the output in your ma.log file. However, by default the logger for the default package (which all data file template classes must currently belong to, so there is no
package com.infiniteautomation
line at the top) is error level and above. This is set in your Mango/classes/log4j2.xml file, which can be copied into Mango/overrides/properties if modified for persistent. You can see the root level defined at line 55,<Root level="error"> <AppenderRef ref="async"/> </Root>
so immediately above that we can define the desired level for our default namespace class like,
<Logger name="YourImporterClassname" level="trace"/>
And then reload the log4j configuration on the old /system_settings.shtm page in the Log4JReset section or restart Mango.
-
Hi Phil,
will this data logger be added to an existing Mango file such as web\modules\dataFile\classes\i18n.properties or data_jsp.class? Or is a new class required to be made?
-
Hi gquiroz,
I do not understand the question. That code was intended to be added into the .java class file that would be placed into the appropriate
Mango/web/modules/dataFile/web/CompilingGrounds/*
folder to be compiled by the tool on the data file data source edit page into a .class file, which is then run to import the file or poll or whatever.