-
Notifications
You must be signed in to change notification settings - Fork 130
Debugging and Logging
When writing a module, it might be a good idea to provide a "debug"-functionality in order to troubleshoot problems that you or other people might experience. Debugging normally increases the verbosity of output for a specific module.
In the MisterHouse INI file, a "Debug" parameter can be set to debug certain parts of MisterHouse.
For modules it is suggested to
- Provide such a debug functionality.
- Anounce the availability of the debug parameter in the code.
- Use the name of your module as option to the Debug-parameter.
Module name "Cool_Item.pm"
Suggested way of enabling debugging in mh.private.ini: "debug=Cool_Item" (Lowercase "debug")
You can debug multiple items by using "**debug=Cool_Item;**Another_Item"
You can have multiple verbosity levels by using: "debug=Cool_Item:9" (Verbosity level 9.)
In your "Cool_Item.pm"-code, the test for this debug flag can be done as follows:
if $main::Debug{cool_item} {
# Execute this only when debugging is enabled
};
Please note the "cool_item" is always automatically converted to lowercase.
$main::Debug{cool_item}
will contain the verbosity level, so you can test if your code is it is higher than a certain threshhold.
When your code needs to output some text, the proposed way is to use the "print_log", or "print_msg" functions. These are available by default and they also provide the functionality to write to a specific logfile instead of the standard logfile. Please see the MH documentation on how to use these.
Do not use "print"-statements.