当前位置: 首页>>代码示例>>Python>>正文


Python Logger.createLogger方法代码示例

本文整理汇总了Python中utils.logger.Logger.createLogger方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.createLogger方法的具体用法?Python Logger.createLogger怎么用?Python Logger.createLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.logger.Logger的用法示例。


在下文中一共展示了Logger.createLogger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_logger

# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import createLogger [as 别名]
 def create_logger(self):
     '''
     Creates and returns the logging object used throughout the application.
     '''
     myLogger = Logger()
     self.set_log_vars_from_config()
     myLogger.LOG_DIR = self.log_dir
     myLogger.LOG_FILENAME = 'RaspiCam.out'
     mylog = myLogger.createLogger(name='RaspiCam')
     
     return mylog
开发者ID:fultonb,项目名称:RaspiCamPiWrap,代码行数:13,代码来源:raspicam.py

示例2: Test

# 需要导入模块: from utils.logger import Logger [as 别名]
# 或者: from utils.logger.Logger import createLogger [as 别名]
class Test(unittest.TestCase):
    
    def setUp(self):
        self.my_log = Logger()


    def tearDown(self):
        self.my_log = None
        

    def test_get_logs_VISUALLY(self):        
        '''
        Creates and prints the following files:
            /tmp/my_test_rotatingfile_example.out
            /tmp/my_test_rotatingfile_example.out.1
            /tmp/my_test_rotatingfile_example.out.2
            /tmp/my_test_rotatingfile_example.out.3
            /tmp/my_test_rotatingfile_example.out.4
            /tmp/my_test_rotatingfile_example.out.5
            
        Then deletes them.
        '''
        # Create test logger.
        self.my_log.LOG_DIR = '/tmp/'
        self.my_log.LOG_FILENAME = 'my_test_rotatingfile_example.out'
        self.my_log.level=logging.DEBUG
        self.my_log.maxBytes = 20
        self.my_log.backupCount = 5
        log = self.my_log.createLogger(name='TestLogger')
        
        # Log some messages.
        for i in range(20):
            log.debug('i = %d' % i)
        
        # See what files are created.
        logfiles = glob.glob('%s*' % self.my_log.LOG_DIR_AND_NAME)
        
        for filename in logfiles:
            print(filename)
        
        # Clean up.
        for filename in logfiles:
            os.remove(filename)
            
            
    def test_format_VISUALLY(self):
        """
        Writes messages to a log file.
        Prints out messages in the log file.
        Deletes the log file.
        """
        # Create default test logger.
        self.my_log.LOG_DIR = '/tmp/'
        log = self.my_log.createLogger(name='MyTestLogger')
        
        log.debug('debug message')
        log.info('info message')
        log.warn('warn message')
        log.error('error message')
        log.critical('critical message')
        
        workfile = self.my_log.LOG_DIR_AND_NAME
        with open(workfile, 'r') as f:
            for line in f:
                print line,

        # See what files are created.
        logfiles = glob.glob('%s*' % self.my_log.LOG_DIR_AND_NAME)
        
        # Clean up.
        for filename in logfiles:
            os.remove(filename)
            
    def test_wrong_file_path(self):
        '''
        File path should revert to default if not found.
        '''
        # Create default test logger.
        self.my_log.LOG_DIR = '/this/path/does/not/exist'
        self.my_log.createLogger(name='MyTestLogger_1')
         
        # See what files are created.
        logfiles = glob.glob('%s*' % self.my_log.LOG_DIR_AND_NAME)
        
        # Clean up.
        for filename in logfiles:
            os.remove(filename)
            
        os.removedirs('./log')
开发者ID:fultonb,项目名称:RaspiCamPiWrap,代码行数:91,代码来源:test_logger.py


注:本文中的utils.logger.Logger.createLogger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。