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


Python logging函数代码示例

本文整理汇总了Python中logging函数的典型用法代码示例。如果您正苦于以下问题:Python logging函数的具体用法?Python logging怎么用?Python logging使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: download

    def download(self):
        result = True

        for file_path, url in self._data:
            local_file = os.path.join(self._destination, file_path)

            dir_name = os.path.dirname(local_file)
            if not os.path.exists(dir_name):
                os.makedirs(dir_name)

            resp = urllib2.urlopen(url)

            try:
                f = open(local_file, 'wb')
                block_size = 8192
                while True:
                    chunk = resp.read(block_size)
                    if not chunk:
                        break
                    f.write(chunk)
            except Exception as e:
                logging("Error while downloading url: ex = {}, url = {}".format(e, url))
            finally:
                f.flush()
                f.close()

        if not result:
            shutil.rmtree(self._destination)

        return result
开发者ID:ZuTa,项目名称:vkbackuper,代码行数:30,代码来源:downloader.py

示例2: get_course_detail

def get_course_detail(category_id):
    try:
        course_info_list = CourseInfo.objects.filter(id = category_id)
        result_info = []
        for info in course_info_list:
            teacher_set = info.course_teacher.all()
            teacher_arr = []
            for teacher in teacher_set:
                teacher_info = {
                    'teacher_id': teacher.id,
                    'teacher_name': teacher.teacher_name,
                    'teacher_photo': teacher.teacher_img,
                    'teacher_level': teacher.teacher_level,
                }
                teacher_arr.append(teacher_info)

            result_item = {
                'course_id': info.id,
                'course_name': info.course_name,
                'course_intro': info.course_intro,
                'course_photo': info.course_img,
                'course_detail': info.course_detail,
                'teacher_arr': teacher_arr,
            }
            result_info.append(result_item)

        return result_info
    except Exception, e:
        logging(e)
        return ERROR_CODE
开发者ID:cslikun,项目名称:bukach-server,代码行数:30,代码来源:home_service.py

示例3: get_hot_info_summary

def get_hot_info_summary():
    try:
        result_info = []
        all_hot_type = HotInfoType.objects.all()
        for type in all_hot_type:
            all_hot_info_per_type = HotInfo.objects.filter(hot_info_type__id = type.id)[0:5]
            hot_content = []
            for hot_info in all_hot_info_per_type:
                ctime = hot_info.hot_date
                dateStr = str(ctime.year) + "-" + str(ctime.month) + "-" + str(ctime.day) + " " \
                      + str(ctime.hour) + ":" + str(ctime.minute) + ":" + str(ctime.second)
                hot_item = {
                    "hot_id": hot_info.id,
                    "hot_date": dateStr,
                    "hot_title": hot_info.hot_info_title,
                    "hot_photo": hot_info.hot_info_title_img,
                }
                hot_content.append(hot_item)
            result_item = {
                "hot_type_id": type.id,
                "hot_type_name": type.hot_info_desc,
                "type_content": hot_content,
            }
            result_info.append(result_item)

        return result_info
    except Exception, e:
        logging(e)
        return ERROR_CODE
开发者ID:cslikun,项目名称:bukach-server,代码行数:29,代码来源:home_service.py

示例4: main

def main():
    try:    
        opener = my_urllib.build_opener(my_urllib.HTTPCookieProcessor)
        my_urllib.install_opener(opener)
    except Exception as e:
        logging.error("url.install_opener() exception : {0}".format(e))
    
    if not getUUID():
        print("获取uuid出错,退出")
        logging('getUUID error,quit')
        return
    
    showQRImage()
    
    while not waitLogin() :
        pass
    
#     os.remove(QRImagePath) #关闭显示图片的窗口,windows不可
    
    if not login():
        print('login fail')
        return

    if not webwxinit():
        print('webwxint fail')
        return
    
    webwxgetcontact()
开发者ID:sherrypoi,项目名称:webchat-deleted-friends,代码行数:28,代码来源:wdf.py

示例5: main

def main():
    p = chdir_myself()
    logging_init("Demo1.log")
    #test_xls()
    test_send_email()
    logging("Exit the program.")
    logging_fini()
开发者ID:oliverhust,项目名称:SendMail,代码行数:7,代码来源:Demo1.py

示例6: checkOptions

def checkOptions(options):

	try:
		int(options.atmost)
	except ValueError:
		logging("atmost must be integer")
		exit(1)

	try:
		int(options.atleast)
	except ValueError:
		logging("atleast must be integer")
		exit(1)

	if options.atmost < 0:
		logging.error("atmost must be non-negative")
		exit(1)

	if options.atleast < 0:
		logging.error("atleast must be non-negative")
		exit(1)

	if options.atmost < options.atleast:
		logging.error("'atmost >= atleast' does not hold")
		exit(1)
开发者ID:KotyVM,项目名称:gofed,代码行数:25,代码来源:scan-packages.py

示例7: get

    def get(self):
        users = WXUser.all()
        p = Push()
        if not users.count():
            return
        opener = poster.streaminghttp.register_openers()
        weatherinfo = json.loads(opener.open(settings.weather1_url % settings.weather_city, timeout=5).read())['weatherinfo']
        logging.info(weatherinfo)
        city = weatherinfo['city']
        temp = weatherinfo['temp']
        wd = weatherinfo['WD']
        ws = weatherinfo['WS']
        sd = weatherinfo['WS']
        time = weatherinfo['time']
        args = (to_unicode(city), temp, to_unicode(wd), to_unicode(ws), sd, time)
        logging(str(args))
        for user in users:
            msg = '''
城市:%s
温度:%s 摄氏度
风向:%s
风力:%s
湿度:%s
发布时间:%s''' % (to_unicode(city), temp, to_unicode(wd), to_unicode(ws), sd, time)
            logging.info(msg)
            p.send_txt_msg(user.fake_id, msg)
开发者ID:qq40660,项目名称:wx,代码行数:26,代码来源:task.py

示例8: validate

def validate(ln_list):
    stop = False
    valid_numbers = []
    #while stop == False:
    for x in ln_list:
        if stop ==False:
            firstcharacters = first_characters(x)
            if len(x) == 0: #handle blank rows
                logging(' This is a BLANK row')
            elif firstcharacters !='' or (firstcharacters ==''and x[0] == '-'): # to handle ' 2' without affecting -999
                if not is_int_or_float(x):
                    if is_int_or_float(firstcharacters):# sc[0]:
                        nc = next_character(x,len(firstcharacters))
                        if nc ==' ' or nc == None:
                            valid_numbers.append(float(firstcharacters))
                            exit
                        else:
                            logging('Though '+str(x)+' starts with integer it is not a valid integer/float')
                    else:
                        logging(str(x)+' is an invalid string with text characters')
                else: #is a +/-ve integer'
                    element = float(x) 
                    if element >=0:
                        valid_numbers.append(float(x))
                    else:                                            
                        if element == -999:
                            stop = True
                        else:
                            logging(str(x)+' is an invalid negative number that is ignored')
            else:
                logging(str(x)+'\'s character is not an integer')
    return valid_numbers
开发者ID:mumbihere,项目名称:general,代码行数:32,代码来源:hw1.monicah_wambugu.py

示例9: _startupActorSys

 def _startupActorSys(self, currentSystemBase, systemBase, capabilities, logDefs):
     self.systemAddress = ActorAddress('/ActorSys')
     self.capabilities = capabilities or dict()
     if 'logging' in self.capabilities:
         import logging
         logging('Thespian').warning('logging specification moved from capabilities to an explicit argument.')
     if systemBase is None:
         systemBase = currentSystemBase
         if systemBase is None:
             import thespian.system.simpleSystemBase
             systemBase = thespian.system.simpleSystemBase.ActorSystemBase(self, logDefs = logDefs)
     elif isinstance(systemBase, str):
         import sys
         if sys.version_info < (2,7):
             import thespian.importlib as importlib
         else:
             import importlib
         # n.b. let standard import exception indicate a missing/unknown systemBase
         module = importlib.import_module('thespian.system.%s'%systemBase)
         sbc = getattr(module, 'ActorSystemBase')
         if currentSystemBase and id(currentSystemBase.__class__) == id(sbc):
             systemBase = currentSystemBase
         else:
             systemBase = sbc(self, logDefs = logDefs)
     elif systemBase and currentSystemBase:
         if id(systemBase.__class__) == id(currentSystemBase.__class__):
             systemBase = currentSystemBase
     # else systemBase should be a valid object already
     self._systemBase = systemBase
     return systemBase
开发者ID:mathewraj,项目名称:Thespian,代码行数:30,代码来源:actors.py

示例10: get_grace_detail

def get_grace_detail(grace_id):
    try:
        all_grace_info = GraceInfo.objects.filter(id = grace_id)
        result_info = []
        for info in all_grace_info:
            img_arr = [];
            if info.grace_img_str is not None:
                img_arr = info.grace_img_str.split("##")
            # img_set = info.grace_content_img.all()
            # for img in img_set:
            #     img_detail = {
            #         'img_location': img.image_location,
            #         'img_height': img.image_height,
            #         'img_width': img.image_width,
            #     }
            #     img_arr.append(img_detail)

            resultItem = {
                'grace_id': info.id,
                'grace_title': info.grace_title,
                'grace_photo': info.grace_title_img,
                'img_height': info.grace_title_img_height,
                'img_width': info.grace_title_img_width,
                'grace_photo_array': img_arr,
            }
            result_info.append(resultItem)

        return result_info
    except Exception, e:
        logging(e)
        return ERROR_CODE
开发者ID:cslikun,项目名称:bukach-server,代码行数:31,代码来源:home_service.py

示例11: add_feedback

def add_feedback(content, email, phone):
    try:
        pub = UserFeedback(feedback_content = content, feedback_email = email, feedback_phone = phone)
        pub.save()
        return "1"
    except Exception, e:
        logging(e)
        return ERROR_CODE
开发者ID:cslikun,项目名称:bukach-server,代码行数:8,代码来源:home_service.py

示例12: setup_environ

def setup_environ():

    # lib
    sys.path.insert(0, os.path.join(ROOT_PATH, 'lib'))

    # SDK (this will be simpler if SDK is in the codebase)
    sdk_path = None
    for path in os.environ.get('PATH').split(os.pathsep):
        if 'dev_appserver.py' in os.listdir(path):
            test_path = os.path.join(path, 'dev_appserver.py')
            sdk_path = os.path.dirname(
                os.readlink(test_path) if os.path.islink(test_path) else test_path)
            break

    if not sdk_path:
        logging.critical("Can't find sdk_path")
        sys.exit(1)
    sys.path.insert(0, sdk_path)

    # Use dev_appserver to set up the python path
    from dev_appserver import fix_sys_path
    fix_sys_path()

    from google.appengine.tools import dev_appserver as tools_dev_appserver
    from google.appengine import dist

    # Parse `app.yaml`
    appinfo, url_matcher, from_cache = tools_dev_appserver.LoadAppConfig(
        ROOT_PATH, {}, default_partition='dev')
    app_id = appinfo.application

    # Useful for later scripts
    os.environ['APPLICATION_ID'] = app_id
    os.environ['APPLICATION_VERSION'] = appinfo.version

    # Third party libraries on the path
    if appinfo.libraries:
        for library in appinfo.libraries:
            try:
                dist.use_library(library.name, library.version)
            except ValueError, e:
                if library.name == 'django' and library.version == '1.4':
                    # Work around an SDK issue
                    logging.warn('django 1.4 not recognised by dist, fixing python path')
                    sys.path.insert(0, os.path.join(sdk_path, 'lib', 'django-1.4'))
                else:
                    logging('Unsupported library:\n%s\n' % e)

            # Extra setup for django
            if library.name == 'django':
                try:
                    import settings
                    from django.core.management import setup_environ
                    setup_environ(settings, original_settings_path='settings')
                except ImportError:
                    logging.error("Could not import django settings")
开发者ID:andrebola,项目名称:potato-example,代码行数:56,代码来源:environ.py

示例13: connectToDatabase

def connectToDatabase(config):
    try:
        conn = psycopg2.connect("dbname='" + config.dbname +
                                "' user='" + config.username +
                                "' host='" + config.host +
                                "' password='" + config.password +
                                "'")
    except:
        logging('I am unable to connect to the database')
    return conn
开发者ID:asl-usgs,项目名称:calanalyzer,代码行数:10,代码来源:Main.py

示例14: set_record_status

 def set_record_status(self, status, wd, time):
     """ Set recorder status """
     for item in self._sched_week[wd]:
         if not item["is_main"]:
             continue
         if item["time"] == time:
             item["record"] = status
             break
     else:
         logging("Program not found")
         return
     self._sched_write_to_file()
开发者ID:petrskovoroda,项目名称:silver-rain,代码行数:12,代码来源:schedule.py

示例15: read_webpage

def read_webpage(url):
    the_page=''
    try:
        req = urllib.request.Request(url)
        response = urllib.request.urlopen(req)
        the_page = response.read().decode(errors='ignore')
    except urllib.error.HTTPError as e:
         logging(e.code)
         logging(e.read())        
    filter_punc = lambda t: ''.join([x.lower() for x in t if x.isalpha()])
    words = [x for x in map(filter_punc, the_page.split()) if x]
    return words
开发者ID:mumbihere,项目名称:general,代码行数:12,代码来源:hw4.monicah.wambugu.py


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