多个py文件共用一个日志

文件try000.py,主文件

	    import logging
		import try001
		
		logger = logging.getLogger('try000')
		logger.setLevel(level=logging.DEBUG)
		
		# Handler
		handler = logging.FileHandler('result.log')
		handler.setLevel(logging.INFO)
		formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
		handler.setFormatter(formatter)
		logger.addHandler(handler)
		
		logger.info('Main Info')
		logger.debug('Main Debug')
		logger.error('Main Error')
		core.run()

文件 try001.py,子文件

	import logging
	import try002
	logger = logging.getLogger('try000.try001')
	
	
	def run():
	    logger.info('Core Info')
	    logger.debug('Core Debug')
	    logger.error('Core Error')
	    try0001.ko123()

文件 try002.py ,子文件

	import logging
	logger = logging.getLogger('try000.try002')
	def ko123():
	    print('hello')
	    logger.info('try0001 Info')
	    logger.debug('try0001 Debug')
	    logger.error('try0001 Error')

你可能感兴趣的:(编码问题)