When importing pyCloudy, a special object is instantiated to hold messages (error, warnings, normal messages and debug tools).
This object is named pc.log_
(considering that pyCloudy is imported as pc). The object is receiving messages, writing them in the standard output (and eventually in a file) and also keeping them in memory. It can also stop the execution and raise an error when error message is sent to it. It also keep the information of which part of the code send the message (the calling), and the time at which is was sent.
There is a level of verbosity, that can be changed at any moment (e.g. pc.log_.level = 2
), which determine the kind of messages that will be printed to the standard output (commonly the screen).
There are 5 types of messages this object is managing:
- debug: using pc.log_.debug('This is the message', calling = 'Routine1'), it is printed if pc.log_level >= 4.
- message: using pc.log_.message('This is the message', calling = 'Routine1'), it is printed if pc.log_level >= 3.
- warning: using pc.log_warn('This is the warning', calling = 'Routine1'), it is printed if pc.log_level >= 2.
- error: using pc.log_error('This is the error', calling = 'Routine1'), it is printed if pc.log_level >= 1. When error is called, an error is raised using exception PyCloudyError, unless the exception argument is given. This default behavior is altered by changing pc.log_.no_exit to False, in which case a SystemExit exception is raised (and the program stops).
- timer: using pc.log_.timer('Ending the process', calling = 'Routine1', quiet = False). This method prints (if quiet = True) the message with the time spent since the last call of timer.ç
It is possible to store the messages in a file. The file if open with pc.log_.open_file('my_log.txt')
, and eventually closed by pc.log_.close_file()
Access to the messages is possible with pc.log_.print_messages(), pc.log_.print_warnings() and pc.log_.print_errors().