Store Log In Variable Python

[Solved] Store Log In Variable Python | Php - Code Explorer | yomemimo.com
Question : create log in python

Answered by : deepakchakravarthy

logging.basicConfig(filename="logfilename.log", level=logging.INFO)
# Log Creation
logging.info('your text goes here')
logging.error('your text goes here')
logging.debug('your text goes here')

Source : https://stackoverflow.com/questions/49580313/create-a-log-file?rq=1 | Last Update : Wed, 04 Nov 20

Question : store log in variable python

Answered by : sachin-verma

#We can use StringIO object for both python2 and python3 like this:
#Python 3 ::
import logging
from io import StringIO
log_stream = StringIO()
logging.basicConfig(stream=log_stream, level=logging.INFO)
logging.info('this is info')
logging.warning('this is warning!')
logging.debug('this is debug')
logging.error('this is error')
logging.critical('oh ,this is critical!')
print(log_stream.getvalue())
#Similarly in Python 2::
import logging
from cStringIO import StringIO
log_stream = StringIO()
logging.basicConfig(stream=log_stream, level=logging.INFO)
logging.info('this is info')
logging.warning('this is warning!')
logging.debug('this is debug')
logging.error('this is error')
logging.critical('oh ,this is critical!')
print(log_stream.getvalue())
######################################
Output ::
INFO:root:this is info
WARNING:root:this is warning!
ERROR:root:this is error
CRITICAL:root:oh ,this is critical!

Source : | Last Update : Wed, 27 Jul 22

Answers related to store log in variable python

Code Explorer Popular Question For Php