From 028de3a13c79a5f007b3d591b79d886f70e41d0f Mon Sep 17 00:00:00 2001 From: Abder Benbachir Date: Wed, 13 Feb 2019 15:07:19 -0800 Subject: [PATCH] improve python-lttngust documentation --- 2.10/lttng-docs-2.10.txt | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/2.10/lttng-docs-2.10.txt b/2.10/lttng-docs-2.10.txt index 1e3b904..f5c33bf 100644 --- a/2.10/lttng-docs-2.10.txt +++ b/2.10/lttng-docs-2.10.txt @@ -5039,19 +5039,26 @@ import lttngust import logging import time - +def add_handler_if_not_exist(logger, handler_class): + handlers = [] + handlers += logger.handlers + handlers += logger.parent.handlers if logger.parent else [] + + if not any([handler for handler in handlers if isinstance(handler, handler_class)]): + logger.addHandler(handler_class()) + def example(): logging.basicConfig() logger = logging.getLogger('my-logger') - - while True: - logger.debug('debug message') - logger.info('info message') - logger.warn('warn message') - logger.error('error message') - logger.critical('critical message') - time.sleep(1) - + # keep logging to stderr even with tracing enabled + add_handler_if_not_exist(logger, logging.StreamHandler) + + logger.debug('debug message') + logger.info('info message') + logger.warn('warn message') + logger.error('error message') + logger.critical('critical message') + time.sleep(1) if __name__ == '__main__': example()