本文整理汇总了Python中common.Log.log方法的典型用法代码示例。如果您正苦于以下问题:Python Log.log方法的具体用法?Python Log.log怎么用?Python Log.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.Log
的用法示例。
在下文中一共展示了Log.log方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Log
# 需要导入模块: from common import Log [as 别名]
# 或者: from common.Log import log [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from urllib import urlopen
import datetime
import time
from common import Log
if __name__ == "__main__":
logfile = '/home/sap/v_jinlchen/integrity.log'
log = Log(logfile)
host = 'http://imeta.ied.com'
day = datetime.date.today() - datetime.timedelta(days=2)
service_list = [1,3,4,49]
url = host + '/index.php/nologin/drIntegrity/%s/' + str(day) + '/1'
if service_list:
for i in service_list:
ret = urlopen(url % i).read()
print ret
time.sleep(1)
if ret == "1":
log_type = 'info'
else:
log_type = 'error'
log.log(ret + " - " + url % i, log_type)
示例2: __init__
# 需要导入模块: from common import Log [as 别名]
# 或者: from common.Log import log [as 别名]
class UpdateAlarmList:
log_obj = None
meta_con = None
meta_cursor = None
def __init__(self, **cfg):
self.log_obj = Log(cfg["log_file"])
self.meta_con = MySQLdb.connect(
host=cfg["db_meta_host"],
user=cfg["db_meta_user"],
passwd=cfg["db_meta_pwd"],
db=cfg["db_meta_name"],
charset="utf8",
use_unicode=True,
cursorclass=MySQLdb.cursors.DictCursor,
)
self.meta_cursor = self.meta_con.cursor()
def getConvergingRecords(self, tbName):
sql = "SELECT iAlarmListID,vFieldInterval,iRelateAlarmListID FROM %s WHERE iDealReport=0" % tbName
self.meta_cursor.execute(sql)
return self.meta_cursor.fetchall()
def getAlarmListInfo(self, alarmListID, tbName):
try:
sql = "SELECT vFieldInterval,vFieldInterDetail FROM %s WHERE iAlarmListID=%s LIMIT 1" % (
tbName,
alarmListID,
)
# self.log("getAlarmListInfo SQL: <%s>" % sql, 'info')
self.meta_cursor.execute(sql)
return self.meta_cursor.fetchone()
except Exception as e:
self.log("getAlarmListInfo: %s, params: <alarmListID: %s, tbName: %s>" % (e, alarmListID, tbName), "error")
def updateIntervalDetail(self, detailStr, alarmListID, tbName):
try:
sql = "UPDATE %s SET vFieldInterDetail='%s' WHERE iAlarmListID='%s' LIMIT 1" % (
tbName,
detailStr,
alarmListID,
)
self.meta_cursor.execute(sql)
self.meta_cursor.execute("commit")
except Exception as e:
self.log(
"updateIntervalDetail: %s, params: <detailStr: %s, alarmListID: %s, tbName: %s>"
% (e, detailStr, alarmListID, tbName),
"error",
)
def getIntervalDetailStr(self, detailStr, interval1, interval2):
diff = self.getHourDiff(interval1, interval2)
length = len(detailStr)
li = list(detailStr)
if length >= diff:
li.append("1")
# li[diff] = '1'
else:
for i in range(diff + 1):
try:
if li[i]:
pass
except IndexError:
if i == diff:
li.append("1")
else:
li.append("0")
return "".join(li)
def getHourDiff(self, interval1, interval2):
ts1 = time.mktime(time.strptime(interval1[0:13], "%Y-%m-%d_%H"))
ts2 = time.mktime(time.strptime(interval2[0:13], "%Y-%m-%d_%H"))
return int((ts2 - ts1) / 3600)
def log(self, msg, level="info"):
self.log_obj.log(msg, level)
示例3: Common
# 需要导入模块: from common import Log [as 别名]
# 或者: from common.Log import log [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from common import Common, Test, Log
a = Common()
b = Test()
#c = Log()
d = Log('./log.log')
b.hello()
#c.log('123123123')
d.log('1231ssssssss23123', 'error')
示例4: __init__
# 需要导入模块: from common import Log [as 别名]
# 或者: from common.Log import log [as 别名]
class TdwIntegrity:
log_obj = None
tdw_con = None
tdw_cursor = None
stat_con = None
stat_cursor = None
meta_con = None
meta_cursor = None
def __init__(self, **cfg):
self.log_obj = Log(cfg['log_file'])
self.meta_con = MySQLdb.connect(host=cfg['db_meta_host'], user=cfg['db_meta_user'], passwd=cfg['db_meta_pwd'],
db=cfg['db_meta_name'], charset='utf8', use_unicode=True,
cursorclass=MySQLdb.cursors.DictCursor)
self.tdw_con = MySQLdb.connect(host=cfg['db_tdw_host'], user=cfg['db_tdw_user'], passwd=cfg['db_tdw_pwd'],
db=cfg['db_tdw_name'], charset='utf8', use_unicode=True,
cursorclass=MySQLdb.cursors.DictCursor)
self.stat_con = MySQLdb.connect(host=cfg['db_stat_host'], user=cfg['db_stat_user'], passwd=cfg['db_stat_pwd'],
db=cfg['db_stat_name'], charset='utf8', use_unicode=True,
cursorclass=MySQLdb.cursors.DictCursor)
self.meta_cursor = self.meta_con.cursor()
self.tdw_cursor = self.tdw_con.cursor()
self.stat_cursor = self.stat_con.cursor()
def getLast7Dasy(self, d):
ret = []
for i in range(8):
tmp = d - datetime.timedelta(days=i)
ret.append(str(tmp))
return ret
def getReportServiceIDs(self):
ret = []
sql = "SELECT iSerID FROM md_service_list WHERE iDailyReport>0"
self.meta_cursor.execute(sql)
for i in self.meta_cursor.fetchall():
ret.append(int(i['iSerID']))
return ret
def getTdwStore(self, serID, date):
ret = 0
tbName = "md_quainterity_res_%s_%s" % (serID, date.replace('-', '')[0:6])
sql = "SELECT SUM(vToResult) as cnt FROM %s WHERE iMetaQuaID=5 AND vFieldInterval LIKE '%s%%'" % (tbName, date)
try:
self.tdw_cursor.execute(sql)
fetchone = self.tdw_cursor.fetchone()
if fetchone['cnt'] > 0:
ret = fetchone['cnt']
except Exception as e:
self.log("getTdwStore: %s, params: [%s, %s]" % (e, serID, date), 'error')
return ret
def insertStatTdwStore(self, data):
sql = "INSERT INTO md_stat_integrity_day (iSerID, iMetaQuaID, dDate, iStore) " \
" VALUES ('%s', '5', '%s', '%s') " % (data['iSerID'], data['dDate'], data['iStore'])
try:
self.stat_cursor.execute(sql)
self.stat_cursor.execute("commit")
except Exception as e:
self.log("%s, params: [%s]" % (e, str(data)), 'error')
def updateStatTdwStore(self, store, iID):
sql = "UPDATE md_stat_integrity_day SET iStore='%s' WHERE iID='%s' " % (store, iID)
try:
self.stat_cursor.execute(sql)
self.stat_cursor.execute("commit")
except Exception as e:
self.log("updateStatTdwStore: %s, params: [store: %s, iID: %s]" % (e, store, iID), 'error')
def checkStatTdwStoreExist(self, data):
ret = 0
sql = "SELECT iID FROM md_stat_integrity_day WHERE iSerID='%s' AND iMetaQuaID=5 AND dDate='%s' LIMIT 1" % (data['iSerID'], data['dDate'])
try:
self.stat_cursor.execute(sql)
fetchone = self.stat_cursor.fetchone()
if fetchone['iID'] > 0:
ret = fetchone['iID']
except Exception as e:
self.log("checkStatTdwStoreExist: %s, params: [%s]" % (e, str(data)), 'error')
finally:
return ret
def checkTop10StoreTableExist(self, serID, date, tbName):
ret = 0
sql = "SELECT iID FROM md_stat_integrity_table WHERE iSerID='%s' AND iMetaQuaID=5 AND dDate='%s' AND vTbName='%s' LIMIT 1" % (serID, date, tbName)
try:
self.stat_cursor.execute(sql)
fetchone = self.stat_cursor.fetchone()
if fetchone['iID'] > 0:
ret = fetchone['iID']
except Exception as e:
self.log("checkTop10StoreTableExist: %s, params: [%s]" % (e, str((serID, date, tbName))), 'error')
finally:
return ret
def tdwTop10StoreTables(self, serID, date):
ret = []
tbName = "md_quainterity_res_%s_%s" % (serID, date.replace('-', '')[0:6])
sql = "SELECT vToDataField, SUM(vToResult) as cnt FROM %s WHERE iMetaQuaID=5 AND vFieldInterval LIKE '%s%%' GROUP BY vToDataField ORDER BY SUM(vToResult) DESC LIMIT 10" % (tbName, date)
try:
self.tdw_cursor.execute(sql)
#.........这里部分代码省略.........