本文整理汇总了Python中models.Log.level方法的典型用法代码示例。如果您正苦于以下问题:Python Log.level方法的具体用法?Python Log.level怎么用?Python Log.level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Log
的用法示例。
在下文中一共展示了Log.level方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_log
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import level [as 别名]
def save_log(request):
'''记录收到的警告记录'''
level = request.POST.get('level', '')
msg = request.POST.get('msg', '')
if not level or not msg:
return HttpResponse(u'参数错误')
try:
level = int(level)
except:
return HttpResponse(u'参数错误')
ip = request.META.get('REMOTE_ADDR', '')
settings = ServerSettings.objects.filter(server_ip=ip)
if settings:
'''找到服务器设置'''
setting = settings[0]
#记录
log = Log()
log.server = setting
log.level = level
log.content = msg
log.save()
print 'log: ', msg
#检查是否推送
push_logs = setting.pushlog_set.order_by('-submit_date')
is_push = False
if push_logs:
#计算时间
push_log = push_logs[0]
now = datetime.datetime.now()
interval = now - push_log.submit_date
if interval.days > 0 or interval.seconds > 30*60:
'''推送间隔要大于30分钟'''
is_push = True
else:
'''没有记录,则要记录'''
is_push = True
if is_push:
'''需要推送'''
print '!!!!!!!!!!!!!!push msg: ', msg
push_log = PushLog()
push_log.server = setting
push_log.content = msg
push_log.save()
return HttpResponse('log ok')
else:
'''没有这个服务器设置'''
return HttpResponse('fail, not setting about this server')
示例2: _to_logs
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import level [as 别名]
def _to_logs(self, hits):
logs = []
for hit in hits:
log = Log()
log.id = hit.meta.id
log.filename = hit.filename
log.level = hit.level
log.message = hit.message
log.created_at = utils.to_datetime(hit.created_at, '%Y-%m-%d')
logs.append(log)
return logs
示例3: emit
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import level [as 别名]
def emit(self, record):
log = Log()
obj = getattr(record, "obj", None)
if obj:
log.obj = unicode(obj)
log.name = unicode(record.name)
log.level = unicode(record.levelname)
log.module = unicode(record.module)
log.func_name = unicode(record.funcName)
log.line_no = unicode(record.lineno)
log.thread = unicode(record.thread)
log.thread_name = unicode(record.threadName)
log.process = unicode(record.process)
log.message = unicode(record.msg)
log.args = unicode(record.args)
db.session.add(log)
db.session.commit()
示例4: emit
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import level [as 别名]
def emit(self, record):
log = Log()
obj = getattr(record, "obj", None)
if obj:
log.obj = repr(obj)
log.name = record.name
log.level = record.levelname
log.module = record.module
log.func_name = record.funcName
log.line_no = record.lineno
log.thread = record.thread
log.thread_name = record.threadName
log.process = record.process
log.message = record.msg
log.args = str(record.args)
db.session.add(log)
db.session.commit()
示例5: gen
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import level [as 别名]
def gen(level, description):
log = Log()
log.description = description
log.level = level
log.create_date = timezone.now()
log.save()