Getting Started: Printing Logs
nominapy uses a custom logger to print messages to the screen in a Python terminal. The logger internally uses the print
function and can print messages in different colours based on the verbosity of the message. For example, error messages are printed in red. For each simulation, and in particular the examples, it is recommended to change the verbosity when attempting to debug the API calls.
Changing the Verbosity
There are four main verbosities on the logger which can be changed based on the messages that are being returned.
LOG
: All messages are outputted to the screen, including information about every single API call made to the REST interface.SUCCESS
: Messages about any successful object creation or errors/warnings are printed, but no individual HTTP requests are shown.WARNING
: Only messages and warnings are shown to the screen which may appear when some task is slow or failing.ERROR
: Only error messages or exceptions are printed on the screen. This is the default verbosity when starting a new simulation unless it is changed.
To change the verbosity, the following can change between the four options for printing to the screen. This will be the same for the entire runtime of the Python file unless changed.
from nominalpy import printer
printer.set_verbosity(printer.LOG_VERBOSITY)
In this example, the following two images compare the result of running the same simulation with the first being the LOG_VERBOSITY
compared to the SUCCESS_VERBOSITY
options.
Printing Logs
Additional logs can be added to the logger by using the printer
module. For each type of log, it will only be displayed on the screen if the correct verbosity is enabled.
from nominalpy import printer
printer.set_verbosity(printer.LOG_VERBOSITY)
printer.log("This is a log.")
printer.success("This is a success message.")
printer.warning("This is a warning.")
printer.error("This is a fatal error.")