#log.py #!/usr/bin/python # -*- coding: utf-8 -*- import logging # logging.debug( u'This is a debug message' ) # logging.info( u'This is an info message' ) # logging.warning( u'This is a warning' ) # logging.error( u'This is an error message' ) # logging.critical( u'FATAL!!!' )
WARNING:root:This is a warning ERROR:root:This is an error message CRITICAL:root:FATAL!!!
logging.basicConfig(level = logging.DEBUG)
#log.py #!/usr/bin/python # -*- coding: utf-8 -*- import logging logging.basicConfig(level = logging.DEBUG) # logging.debug( u'This is a debug message' ) # logging.info( u'This is an info message' ) # logging.warning( u'This is a warning' ) # logging.error( u'This is an error message' ) # logging.critical( u'FATAL!!!' )
DEBUG:root:This is a debug message INFO:root:This is an info message WARNING:root:This is a warning ERROR:root:This is an error message CRITICAL:root:FATAL!!!
logging.basicConfig(format = u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s', level = logging.DEBUG)
log.py[LINE:33]# DEBUG [2012-05-25 00:11:58,466] This is a debug message log.py[LINE:34]# INFO [2012-05-25 00:11:58,466] This is an info message log.py[LINE:35]# WARNING [2012-05-25 00:11:58,466] This is a warning log.py[LINE:36]# ERROR [2012-05-25 00:11:58,467] This is an error message log.py[LINE:37]# CRITICAL [2012-05-25 00:11:58,467] FATAL!!!
logging.basicConfig(format = u'%(levelname)-8s [%(asctime)s] %(message)s', level = logging.DEBUG, filename = u'mylog.log')
Source: https://habr.com/ru/post/144566/
All Articles