vispy.util.logs module#
- class vispy.util.logs.NumPyJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#
Bases:
JSONEncoder
- default(obj)#
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- vispy.util.logs.log_exception(level='warning', tb_skip=2)#
Send an exception and traceback to the logger.
This function is used in cases where an exception is handled safely but nevertheless should generate a descriptive error message. An extra line is inserted into the stack trace indicating where the exception was caught.
- Parameters:
- levelstr
See
set_log_level
for options.- tb_skipint
The number of traceback entries to ignore, prior to the point where the exception was caught. The default is 2.
- vispy.util.logs.set_log_level(verbose, match=None, return_old=False)#
Convenience function for setting the logging level
- Parameters:
- verbosebool, str, int, or None
The verbosity of messages to print. If a str, it can be either DEBUG, INFO, WARNING, ERROR, or CRITICAL. Note that these are for convenience and are equivalent to passing in logging.DEBUG, etc. For bool, True is the same as ‘INFO’, False is the same as ‘WARNING’.
- matchstr | None
String to match. Only those messages that both contain a substring that regexp matches
'match'
(and theverbose
level) will be displayed.- return_oldbool
If True, return the old verbosity level and old match.
See also
vispy.util.use_log_level
Notes
If
verbose=='debug'
, then thevispy
method emitting the log message will be prepended to each log message, which is useful for debugging. Ifverbose=='debug'
ormatch is not None
, then a small performance overhead is added. Thus it is suggested to only use these options when performance is not crucial.
- class vispy.util.logs.use_log_level(level, match=None, record=False, print_msg=True)#
Bases:
object
Context manager that temporarily sets logging level
- Parameters:
- levelstr
See
set_log_level
for options.- matchstr | None
The string to match.
- recordbool
If True, the context manager will keep a record of the logging messages generated by vispy. Otherwise, an empty list will be returned.
- print_msgbool
If False, printing of (all) messages will be suppressed. This is mainly useful in testing. False only works in record=True mode, if not recording messages, consider setting level appropriately.
- Returns:
- recordslist
As a context manager, an empty list or the list of logging messages will be returned (depending on the input
record
).