Table of Contents
02 Getting Started
Only few steps are necessary to initialize an HSE Logger instance. After that, it's enough to just drop log-VIs (e.g. DEBUG.vi, INFO.vi, …) on the block diagram and give them a descriptive log message.
Initialization
One of the first things a program should do is to start a logging system to track all important events as early as possible.
The HSE Logger gets initialized with the Init Logging.vi
, which itself expects two inputs. Like the terminal name indicates it, “Name” must be wired to a string with an arbitrary name for that logger. Usually we use only one logger in a program, hence the name isn't so important. The second required terminal needs an array of Handler
objects. These Handler
objects are responsible for the actual writing of the log information to a sink, e.g. a file.
The open source version of the HSE Logger ships with two Handler
classes, the FileHandler
and UserEventHandler
. Take a look at our HSE Logger Extensions section for more Handlers.
Each Handler must be initialized and need a minimal set of parameters, a name and level (an enumerator) which sets the minimum log-level this handler processes. Some Handler classes may need more parameter, e.g. the FileHandler
needs a file path to define the log file it writes into.
After the Init Logging
VI was called successfully, the logger is ready and can be used.
Initialization of a UserEventHandler
(top) and a FileHandler
(bottom). Both handlers get bundled into an array and feed into Init Logging
to start the logger.
Usage
The easiest way to log an event is to drop an appropriate Logger-VI from the HSE Logger pallet or via Quick-Drop on the block terminal and wire a descriptive message. Usually the logger-VIs are included in the error wires to carry the error information as well.
That's all
Formatters
New with version 2.1.0 is the possibility to use a Formatter object to format the log information into different string representations. Handler classes that produce formatted output, like the FileHandler
use the Formatter.Format LogRecord
method internally. Not every Handler object use a Formatter, e.g. the UserEventHandler
does not format its output (the user event returns a LogRecord
object). But the developer can user the Formatter
classes to generate a formatted string afterward.
All Handler
classes which support a Formatter
have an input terminal in there “Create” method and support the Set/Get Formatter
methods. See the initialization-screenshot above.
A convenient way to use the UserEventHandler
in a DQMH API Tester VI and in combination with a Formatter
is shown in the screenshot below. In this scenario, the HSE Logger is initialized in the very first VI DQMH Tester Prepare hse-appl.vi
which is part of our HSE Libraries.