# logging
import logging
logging.basicConfig(level=logging.INFO)
logging.debug('This message will be ignored')
logging.info('This should be logged')
logging.warning('And this, too')
# 결과
INFO:root:This should be logged
WARNING:root:And this, too
# 상수
print(logging.DEBUG)
print(logging.INFO)
print(logging.WARNING)
# 결과
10
20
30
# 파일 저장
import logging
logging.basicConfig(level=logging.INFO, filename='logs.txt', filemode='w')
logging.debug('This message will be ignored')
logging.info('This should be logged')
logging.warning('And this, too')
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
# logging.disable(logging.CRITICAL)
def buggy_factorial(n):
logging.debug('Start of factorial (%s)' % (n))
total = 1
for i in range(n+1):
total *= i
logging.debug('i is %s, total is %s' % (i, total))
logging.debug('Return value is %s' % (total))
return total
print(buggy_factorial(5))
# 결과
2016-06-10 15:32:53,441 - DEBUG - Start of factorial (5)
2016-06-10 15:32:53,441 - DEBUG - i is 0, total is 0
2016-06-10 15:32:53,441 - DEBUG - i is 1, total is 0
2016-06-10 15:32:53,441 - DEBUG - i is 2, total is 0
2016-06-10 15:32:53,441 - DEBUG - i is 3, total is 0
2016-06-10 15:32:53,441 - DEBUG - i is 4, total is 0
2016-06-10 15:32:53,441 - DEBUG - i is 5, total is 0
2016-06-10 15:32:53,441 - DEBUG - Return value is 0
0
댓글 영역