_log module

class pyflyby._log.PyflybyLogger(name, level)
HookCtx(pre, post)
_LEVELS = {'DEBUG': 10, 'ERROR': 40, 'INFO': 20, 'WARNING': 30}
property debug_enabled
property info_enabled
set_level(level)

Set the pyflyby logger’s level to level.

pyflyby._log._NoRegisterLoggerHandlerInHandlerListCtx()

Work around a bug in the logging module for Python 2.x-3.2.

The Python stdlib logging module has a bug where you sometimes get the following warning at exit:

Exception TypeError: "'NoneType' object is not callable" in <function
_removeHandlerRef at 0x10a1b3f50> ignored

This is caused by shutdown ordering affecting which globals in the logging module are available to the _removeHandlerRef function.

Python 3.3 fixes this.

For earlier versions of Python, this context manager works around the issue by avoiding registering a handler in the _handlerList. This means that we no longer call “flush()” from the atexit callback. However, that was a no-op anyway, and even if we needed it, we could call it ourselves atexit.

See

http://bugs.python.org/issue9501

pyflyby._log._PromptToolkitStdoutProxyRawCtx(proxy)

Hack to defeat the “feature” where prompt_toolkit.interface._StdoutProxy(sys.stderr) causes ANSI escape codes to not be written.

class pyflyby._log._PyflybyHandler(level=0)
HookCtx(pre, post)
Enter a context where:
  • pre is called before the first time a log record is emitted during the context, and

  • post is called at the end of the context, if any log records were emitted during the context.

Parameters
  • pre (callable) – Function to call before the first time something is logged during this context.

  • post (callable) – Function to call before returning from the context, if anything was logged during the context.

_interactive_prefix = '\x1b[0m\x1b[33m[PYFLYBY]\x1b[0m '
_logged_anything_during_context = False
_noninteractive_prefix = '[PYFLYBY] '
_pre_log_function = None
emit(record)

Emit a log record.

pyflyby._log._is_interactive(file)
pyflyby._log._is_ipython()

Returns true if we’re currently running inside IPython.