Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve python-lttngust documentation #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions 2.10/lttng-docs-2.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down