本文整理汇总了Python中toughlib.logger.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_events
def load_events(event_path=None, pkg_prefix=None, excludes=[], event_params={}):
_excludes = ["__init__", "settings"] + excludes
evs = set(os.path.splitext(it)[0] for it in os.listdir(event_path))
evs = [it for it in evs if it not in _excludes]
for ev in evs:
try:
sub_module = os.path.join(event_path, ev)
if os.path.isdir(sub_module):
# logger.info('load sub event %s' % ev)
load_events(
event_path=sub_module,
pkg_prefix="{0}.{1}".format(pkg_prefix, ev),
excludes=excludes,
event_params=event_params,
)
_ev = "{0}.{1}".format(pkg_prefix, ev)
# logger.info('load_event %s with params:%s' % (_ev,repr(event_params)))
robj = importlib.import_module(_ev)
if hasattr(robj, "evobj"):
dispatch.register(robj.evobj)
if hasattr(robj, "__call__"):
dispatch.register(robj.__call__(**event_params))
except Exception as err:
logger.error("%s, skip module %s.%s" % (str(err), pkg_prefix, ev))
import traceback
traceback.print_exc()
continue
示例2: disconnect
def disconnect(self):
try:
is_chap=self.settings.config.portal.chap in (1, "1", "chap")
userIp = self.current_user.ipaddr
nas = self.get_nas(self.current_user.nasaddr)
ac_addr = nas['ip_addr']
ac_port = int(nas['ac_port'])
secret = utils.safestr(nas['bas_secret'])
_vendor= utils.safestr(nas['portal_vendor'])
if _vendor not in ('cmccv1','cmccv2','huaweiv1','huaweiv2'):
defer.returnValue("not support vendor %s"%_vendor)
send_portal = functools.partial(
client.send,
secret,
log=self.syslog,
debug=self.settings.debug,
vendor=_vendor
)
vendor = client.PortalClient.vendors.get(_vendor)
logout_req = vendor.proto.newReqLogout(userIp, secret,chap=is_chap)
logout_resp = yield send_portal(data=logout_req, host=ac_addr, port=ac_port)
if logout_resp.errCode > 0:
_err_msg=u"{0},{1}".format(
vendor.mod.AckLogoutErrs[logout_resp.errCode],
utils.safeunicode(logout_resp.get_text_info()[0] or "")
)
logger.error( _err_msg)
defer.returnValue("disconnect done!")
except Exception as err:
defer.returnValue(err)
示例3: event_toughcloud_mail_account_open
def event_toughcloud_mail_account_open(self, userinfo):
""" toughCloud mail api open notify without password event """
if not userinfo:
return
if not userinfo.get('email'):
logger.error('user email is None exit')
return
try:
api_secret = self.get_param_value("toughcloud_license")
service_mail = self.get_param_value("toughcloud_service_mail")
if not service_mail:
return
api_token = yield tools.get_sys_token()
params = dict(
token=api_token.strip(),
action='email',
mailto=userinfo.get('email'),
tplname=self.MAIL_TPLNAME,
customer=utils.safestr(userinfo.get('realname')),
username=userinfo.get('account_number'),
product=utils.safestr(userinfo.get('product_name')),
expire=userinfo.get('expire_date'),
service_call=self.get_param_value("toughcloud_service_call", ''),
service_mail=service_mail,
nonce=str(int(time.time()))
)
params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
resp = yield httpclient.fetch(self.MAIL_APIURL, postdata=urlencode(params))
logger.info(resp.body)
logger.info('open account send email without password success')
except Exception as err:
logger.exception(err)
示例4: onSendError
def onSendError(self,err, disconnect_req):
if disconnect_req and self.db.query(models.TrOnline).filter_by(
nas_addr=disconnect_req.nas_addr,
acct_session_id=disconnect_req.acct_session_id).count() > 0:
radius_acct_stop.RadiusAcctStop(
self.dbengine,self.mcache,self.aes, disconnect_req).acctounting()
logger.error(u"send disconnect done! %s" % err.getErrorMessage())
示例5: process
def process(self):
conn = self.db()
try:
nas_list = conn.query(models.TrwBas)
for nas in nas_list:
if not nas.dns_name:
continue
results, _, _ = yield client.lookupAddress(nas.dns_name)
if not results:
logger.error("domain {0} resolver empty".format(nas.dns_name))
if results[0].type == dns.A:
ipaddr = ".".join(str(i) for i in struct.unpack("BBBB", results[0].payload.address))
if ipaddr:
nas.ip_addr = ipaddr
conn.commit()
logger.info("domain {0} resolver {1} success".format(nas.dns_name,ipaddr))
else:
logger.info("domain {0} no ip address,{1}".format(nas.dns_name, repr(results)))
except Exception as err:
logger.error('ddns process error %s' % utils.safeunicode(err.message))
finally:
conn.close()
reactor.callLater(60, self.process, )
示例6: process
def process(self, *args, **kwargs):
next_interval = self.get_notify_interval()
user_total = 0
online_total = 0
with make_db(self.db) as db:
try:
user_total = db.query(models.TrAccount).count()
online_total = db.query(models.TrOnline).count()
except Exception as err:
pass
try:
api_url = "https://www.toughcloud.net/api/v1/ping"
api_token = yield tools.get_sys_token()
params = dict(
token=api_token,
app="toughradius",
ver=__version__,
release=self.config.system.get('release',"standard"),
unum=user_total,
onum=online_total,
dist=' '.join(pf.linux_distribution()),
)
param_str = urlencode(params)
resp = yield httpclient.fetch(api_url+"?"+param_str,followRedirect=True)
logger.info("toughcloud ping resp code: %s"%resp.code)
except Exception as err:
logger.error(err)
defer.returnValue(next_interval)
示例7: process
def process(self, *args, **kwargs):
self.logtimes()
next_interval = self.get_notify_interval()
backup_path = self.config.database.backup_path
backup_file = "trdb_cron_backup_%s.json.gz" % utils.gen_backep_id()
try:
self.db_backup.dumpdb(os.path.join(backup_path, backup_file))
logger.info(u"数据备份完成,下次执行还需等待 %s"%(self.format_time(next_interval)) )
except Exception as err:
logger.error(u"数据备份失败,%s, 下次执行还需等待 %s"%( repr(err), self.format_time(next_interval)) )
logger.exception(err)
try:
bak_list = [ bd for bd in os.listdir(backup_path) if 'trdb_cron_backup' in bd]
if len(bak_list) > 7:
logger.info("find expire backup file and remove")
_count = 0
for fname in bak_list:
fpath = os.path.join(backup_path, fname)
if (time.time() - os.path.getctime(fpath)) > 14:
os.remove(fpath)
_count += 1
logger.info("remove expire backup file %s"%fpath)
logger.info("remove expire backup file total %s"%_count)
except Exception as err:
logger.exception(err)
return next_interval
示例8: processAcct
def processAcct(self, datagram, host, port):
try:
bas = self.find_nas(host)
if not bas:
raise PacketError('[Radiusd] :: Dropping packet from unknown host %s' % host)
secret, vendor_id = bas['bas_secret'], bas['vendor_id']
req = self.createAcctPacket(packet=datagram,
dict=self.dict, secret=six.b(str(secret)),vendor_id=vendor_id)
logger.info("[Radiusd] :: Received radius request: %s" % (repr(req)))
if self.config.system.debug:
logger.debug(req.format_str())
if req.code != packet.AccountingRequest:
raise PacketError('non-AccountingRequest packet on authentication socket')
if not req.VerifyAcctRequest():
raise PacketError('VerifyAcctRequest error')
reply = req.CreateReply()
status_type = req.get_acct_status_type()
if status_type in self.acct_class:
acct_func = self.acct_class[status_type](self,req.get_ticket()).acctounting
reactor.callLater(0.1,acct_func)
return reply
except Exception as err:
errstr = 'RadiusError:Dropping invalid acct packet from {0} {1},{2}'.format(
host, port, utils.safeunicode(err))
logger.error(errstr)
import traceback
traceback.print_exc()
示例9: process
def process(self, *args, **kwargs):
with make_db(self.db) as db:
try:
nodes = db.query(models.TrNode)
for node in nodes:
online_count = (
db.query(models.TrOnline.id)
.filter(
models.TrOnline.account_number == models.TrAccount.account_number,
models.TrAccount.customer_id == models.TrCustomer.customer_id,
models.TrCustomer.node_id == node.id,
)
.count()
)
stat = models.TrOnlineStat()
stat.node_id = node.id
stat.stat_time = int(time.time())
stat.total = online_count
db.add(stat)
db.commit()
logger.info("online stat task done")
except Exception as err:
db.rollback()
logger.error("online_stat_job err,%s" % (str(err)))
return 120.0
示例10: process
def process(self, *args, **kwargs):
self.logtimes()
with make_db(self.db) as db:
try:
nodes = db.query(models.TrNode)
for node in nodes:
r = db.query(
func.sum(models.TrOnline.input_total).label("input_total"),
func.sum(models.TrOnline.output_total).label("output_total")
).filter(
models.TrOnline.account_number == models.TrAccount.account_number,
models.TrAccount.customer_id == models.TrCustomer.customer_id,
models.TrCustomer.node_id == node.id
).first()
if r and all([r.input_total,r.output_total]):
stat = models.TrFlowStat()
stat.node_id = node.id
stat.stat_time = int(time.time())
stat.input_total = r.input_total
stat.output_total = r.output_total
db.add(stat)
# clean expire data
_time = int(time.time()) - (86400 * 2)
db.query(models.TrFlowStat).filter(models.TrFlowStat.stat_time < _time).delete()
db.commit()
logger.info("flow stat task done")
except Exception as err:
db.rollback()
logger.error('flow_stat_job err,%s'%(str(err)))
return self.get_notify_interval()
示例11: event_toughcloud_sms_account_open
def event_toughcloud_sms_account_open(self, userinfo):
""" toughCloud sms api open notify event """
if not userinfo:
return
if not userinfo.get('phone'):
logger.error('user phone is None exit')
return
api_secret = self.get_param_value("toughcloud_license")
api_token = yield tools.get_sys_token()
params = dict(
token=api_token.strip(),
action='sms',
tplname=self.SMS_TPLNAME,
phone=userinfo.get('phone'),
customer=utils.safestr(userinfo.get('realname')),
username=userinfo.get('account_number'),
product=utils.safestr(userinfo.get('product_name')),
password=userinfo.get('password'),
expire=userinfo.get('expire_date'),
nonce=str(int(time.time()))
)
params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
try:
resp = yield httpclient.fetch(self.SMS_APIURL, postdata=urlencode(params))
logger.info(resp.body)
logger.info('open account send short message success')
except Exception as err:
logger.exception(err)
示例12: parse_form_request
def parse_form_request(self):
try:
print self.get_params()
return apiutils.parse_form_request(self.settings.config.system.secret, self.get_params())
except Exception as err:
logger.error(u"api authorize parse error, %s" % utils.safeunicode(traceback.format_exc()))
raise ValueError(u"Error: %s" % utils.safeunicode(err.message))
示例13: process
def process(self, *args, **kwargs):
try:
self.statdata.run_stat()
if self.cache.get(radius_statcache_key):
self.cache.update(radius_statcache_key,self.statdata)
else:
self.cache.set(radius_statcache_key,self.statdata)
except Exception as err:
logger.error('radius stat process error %s' % utils.safeunicode(err.message))
return 10.0
示例14: init_route_permit
def init_route_permit(self):
with make_db(self.db) as conn:
try:
oprs = conn.query(models.TrOperator)
for opr in oprs:
if opr.operator_type > 0:
for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=opr.operator_name):
permit.bind_opr(rule.operator_name, rule.rule_path)
elif opr.operator_type == 0: # 超级管理员授权所有
permit.bind_super(opr.operator_name)
except Exception as err:
logger.error("init route error , %s" % str(err))
示例15: process
def process(self, *args, **kwargs):
next_interval = self.get_notify_interval()
try:
api_url = "https://www.toughcloud.net/api/v1/ping"
api_token = yield tools.get_sys_token()
param_str = urlencode({'token':api_token})
resp = yield httpclient.fetch(api_url+"?"+param_str,followRedirect=True)
logger.info("toughcloud ping resp code: %s"%resp.code)
if resp.code == 200:
self.cache.set(toughcloud_ping_key,resp.body,expire=3600)
except Exception as err:
logger.error(err)
defer.returnValue(next_interval)