Skip to content

Instantly share code, notes, and snippets.

View prabhuSub's full-sized avatar
👾
Focusing

Prabhu Subramanian prabhuSub

👾
Focusing
View GitHub Profile
@prabhuSub
prabhuSub / logging_to_str.py
Created December 12, 2020 10:29 — forked from 66Ton99/logging_to_str.py
Capturing Python Log Output In A Variable
import logging
from StringIO import StringIO as StringBuffer
logger = logging.getLogger('basic_logger')
logger.setLevel(logging.DEBUG)
### Setup the console handler with a StringIO object
log_capture_string = StringBuffer()
# log_capture_string.encoding = 'cp1251'
ch = logging.StreamHandler(log_capture_string)