Skip to content

Instantly share code, notes, and snippets.

View FluffyDietEngine's full-sized avatar
🤓
Grateful

Santhosh Solomon FluffyDietEngine

🤓
Grateful
  • Advarisk
  • Pune
View GitHub Profile
@66Ton99
66Ton99 / logging_to_str.py
Created August 28, 2015 16:26
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)