display module¶
-
class
Displayer(statistician=None, display_period=10, console_print_program_log=True, write_program_log_file=True, log_level=30, debug=False)[source]¶ Bases:
threading.ThreadThis thread object is responsible for the logging and the printing of the stats, the alerts and the log messages. The log messages are messages generated by the different threads to inform the user of a peculiar event.
This thread can keep up to two output log files : one for the traffic alerts, and one for the log messages. The alert log is always used, the program log is optional, by default activated.
The log messages can also be printed on the console.
Note
Once it has been initiated (for instance with
picasso = Displayer(debug=True), itslog()method can be simply called from any module with the following code:import display as d d.log(self, d.LogLevel.INFO, "This is my log message !")
This is possible because in
__init__(), it defines aglobal displayervariable.Variables: - statistician (Statistician) – A reference to the statistician that will be contacted to print the stats.
- display_period (int) – The stats will be printed with a period = display_period
- log_level (LogLevel) – The limit under which received log messages will simply be ignored in the log method
- console_print_program_log (bool) – If true, the receive log messages will be printed in the console, if their log_level is above or equal to the log_level
- write_program_log_file (bool) – If true, the receive log messages will be written in the program log file, if their log_level is above or equal to the log_level
- should_run (bool) – If False, the thread will shortly end stop its operation. Used to cleanly end the program.
- registered_object (list of Thread) – The list of other threads, used of INFO log messages
- console_lock (Lock) – Lock used to make the print function thread-safe
- display_width (int) – The typical width of the terminal
- name (string) –
-
log(sender, level, message)[source]¶ Receives messages from all the threads and “thread-safely” prints them depending of their level. Writes them on the log file if needed.
Parameters: - sender (Object) – A reference to the sender
- level (LogLevel) – The log level of the message
- message (string) – The message
-
print_end_alert(alert_param, long_average, short_average)[source]¶ Called when a alert is shut down, prints and/or logs it
Note
Could be merged with
print_new_alert
-
print_new_alert(alert_param, long_average, short_average)[source]¶ Called when a alert is raised, prints and/or logs it
Parameters: - alert_param (AlertParam) –
- long_average (float) –
- short_average (float) –
-
class
LogLevel[source]¶ Stores the possible values of the log printing parameters
log_level.This is an ersatz to an Enumerate object (not available in python2).
level_nameis used to get thelog_levelname from its value.-
CRITICAL= 50¶
-
DEBUG= 10¶
-
ERROR= 40¶
-
INFO= 20¶
-
WARNING= 30¶
-
level_name= {40: u'ERROR', 10: u'DEBUG', 20: u'INFO', 50: u'CRITICAL', 30: u'WARNING'}¶
-