本文整理汇总了Python中moat.logging.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: got_entry
def got_entry(name):
if key is None and name.startswith("bus."):
buses.append(name)
elif len(name)>3 and name[2] == ".":
entries.append(name)
else:
log("onewire",TRACE,"got unrecognized name %s" % (name,))
示例2: get_collect
def get_collect(name, allow_collection=False):
c = None
if not len(name):
return None
coll = collections
if allow_collection and name[-1] == "*":
return coll[Name(*name[:-1])]
while len(name):
n = len(name)
while n > 0:
try:
coll = coll[Name(*name[:n])]
except KeyError:
n = n-1
else:
name = name[n:]
if c is None: c = coll
break
if n == 0:
try:
coll = coll[name[0]]
except KeyError:
from moat.logging import DEBUG,log
log(DEBUG,"Contents: "+", ".join(str(x) for x in coll.keys()))
raise CKeyError(name,coll)
else:
name = name[1:]
if c is None: c = coll
if not allow_collection and not isinstance(coll,Collected):
raise CCollError(name)
return coll
示例3: lineReceived
def lineReceived(self,data):
db = ""
e = ""
if not data: return # empty line
if data[0] in PREFIX:
for d in data[1:]:
if e:
try:
db += chr(eval("0x"+e+d))
except SyntaxError:
simple_event("fs20","unknown","hex", data=data)
return
e=""
else:
e=d
if e:
log("fs20",WARN,"fs20 odd length "+data)
self.datagramReceived(data[0], db, timestamp=self.timestamp)
self.timestamp = None
elif data[0] == PREFIX_TIMESTAMP:
self.timestamp = float(data[1:])
elif data[0] == "P":
pass # idle
elif data[0] == "+":
log("fs20",DEBUG,"fs20 trace "+data)
else:
simple_event("fs20","unknown","prefix", prefix=data[0],data=data[1:])
示例4: _do_measure
def _do_measure(self):
log("monitor",TRACE,"Start run",self.name)
try:
self.running.clear()
self.started_at = now()
self._monitor()
if self.send_check_event:
simple_event(self.ectx, "monitor","checked",*self.name)
if self.new_value is not None:
self.last_value = self.value
self.value = self.new_value
if hasattr(self,"delta"):
if self.last_value is not None:
val = self.value-self.last_value
self._ectx.value_delta = val
if val >= 0 or self.delta == 0:
simple_event(self.ectx,"monitor","update",*self.name)
else:
simple_event(self.ectx,"monitor","update",*self.name)
except Exception as e:
fix_exception(e)
process_failure(e)
finally:
log("monitor",TRACE,"Stop run",self.name)
self.running.set()
self._schedule()
示例5: dataReceived
def dataReceived(self, data):
self._stop_timer()
data = self.dbuf+data
while True:
xi = len(data)+1
try: pi = data.index(b'\r')
except ValueError: pi = xi
try: ei = data.index(b'\n')
except ValueError: ei = xi
if pi==xi and ei==xi:
break
if pi < ei:
self.lbuf = data[:pi].decode('utf-8')
data = data[pi+1:]
else:
msg = data[:ei].decode('utf-8')
data = data[ei+1:]
if msg == "" and self.lbuf is not None:
msg = self.lbuf
self.lbuf = None
try:
self.lineReceived(msg)
except Exception as e:
log("fs20",ERROR,msg,e)
fix_exception(e)
process_failure(e)
self.dbuf = data
self._start_timer()
示例6: up
def up(self):
dev = devices[self.device]
if self.switch is not None and self.switched is None:
log(DEBUG,"switch low1",self.switch,self.to_low)
dev.set(self.switch,self.to_low)
self.switched = False
return super(OWFSmon,self).up()
示例7: error
def error(self,err):
"""An error occurred."""
if self.result is not None and not self.result.successful:
log("onewire",DEBUG,"done error: ",self,err)
self.result.set_exception(err)
else:
process_failure(err)
示例8: run
def run(self,ctx,**k):
event = self.params(ctx)
try:
out = self.ctx.out
except AttributeError:
out = sys.stderr
if not len(event):
for s,v in LogNames.items():
print("%d = %s" % (s,v), file=out)
print(".", file=out)
return None
if len(event) > 1:
log(getattr(logging,event[0].upper()), *event[1:])
else:
level = getattr(logging,event[0].upper())
if level == logging.NONE:
if hasattr(out,"logger"):
out.logger.delete()
del out.logger
else:
if hasattr(out,"logger"):
out.logger.level = level
else:
try: out = self.ctx.out
except AttributeError: out = sys.stderr
logger = OutLogger(out=out, level=level)
try: out.logger = logger
except AttributeError: pass # file objects don't
except:
logger.delete()
raise
示例9: exposed_write
def exposed_write(self,s):
i = s.find("\n")
while i >= 0:
log("TEST",DEBUG,">>>",self.buf+s[:i])
self.buf = ""
s = s[i+1:]
i = s.find("\n")
self.buf += s
示例10: _init
def _init(self, bus, short_id=None, id=None, path=()):
log("onewire",DEBUG,"NEW", bus,short_id,id,path)
self.bus_id = id
if short_id:
self.id = short_id.lower()
self.bus = bus
assert path is not None
self.path = path
self.is_up = None
self.ctx = Context()
示例11: do_post
def do_post(self):
self.slotter = None
if self.running != "during" or self.waiter is not None:
log(ERROR,"timeslot error post",self.running,*self.name)
return
self.running = "next"
simple_event("timeslot","end",*self.name, deprecated=True)
simple_event("timeslot","state",*self.name, state="end")
self.next = time_delta(self.interval, now=self.next)-dt.timedelta(0,self.duration)
self.waiter = callLater(False, self.next, self.do_pre)
示例12: _update_all
def _update_all(self):
log("onewire",TRACE,"start bus update")
old_ids = devices.copy()
new_ids = {}
seen_ids = {}
old_bus = set(self.bus_paths.keys())
new_bus = set()
def bus_cb(path):
if path in old_bus:
old_bus.remove(path)
else:
new_bus.add(path)
for dev in self.all_devices(bus_cb):
if dev.id in seen_ids:
continue
seen_ids[dev.id] = dev
if dev.id in old_ids:
del old_ids[dev.id]
else:
new_ids[dev.id] = dev
n_old = 0
n_dev = 0
for dev in old_ids.values():
if dev.bus is self:
n_old += 1
## Just because something vanishes from the listing
## doesn't mean it's dead; the bus may be a bit unstable
# dev.go_down()
log("onewire",DEBUG,"Bus unstable?",self.name,dev.id)
for dev in devices.values():
if dev.bus is self:
n_dev += 1
for dev in old_bus:
bp = self.bus_paths.pop(dev)
bp.stop()
simple_event("onewire","bus","down", bus=self.name,path=dev)
simple_event("onewire","bus","state",self.name,"/".join(dev), bus=self.name,path=dev, state="down")
for dev in new_bus:
self.bus_paths[dev] = OWFSbuspath(self,dev)
simple_event("onewire","bus","up", bus=self.name,path=dev)
simple_event("onewire","bus","state",self.name,"/".join(dev), bus=self.name,path=dev, state="up")
# success only, error above
simple_event("onewire","scanned",*self.name, old=n_old, new=len(new_ids), num=n_dev, deprecated=True)
simple_event("onewire","scan",*self.name, run="done", old=n_old, new=len(new_ids), num=n_dev)
示例13: lineReceived
def lineReceived(self, line):
log("wago",TRACE,"recv",repr(line))
msgid = 0
off = 0
mt = MT_OTHER
if self.buf is not None:
if line == ".":
buf,self.buf = self.buf,None
self.msgReceived(type=MT_MULTILINE, msg=buf)
else:
if line.startswith("."):
line = line[1:]
self.buf.append(line)
return
elif line == "":
self.msgReceived(type=MT_OTHER, msg=line)
elif line[0] == "=":
self.buf = [line[1:]]
return
elif line[0] == "?":
self.msgReceived(type=MT_ERROR, msg=line[1:].strip())
return
elif line[0] == "*":
self.msgReceived(type=MT_INFO, msg=line[1:].strip())
return
elif line[0] == "+":
self.msgReceived(type=MT_ACK, msg=line[1:].strip())
return
elif line[0] == "-":
self.msgReceived(type=MT_NAK, msg=line[1:].strip())
return
elif line[0] == "!":
if line[1] == "+":
mt = MT_IND_ACK
off = 2
elif line[1] == "-":
mt = MT_IND_NAK
off = 2
else:
mt = MT_IND
off = 1
while off < len(line) and line[off].isdigit():
msgid = 10*msgid+int(line[off])
off += 1
if msgid > 0:
self.msgReceived(type=mt, msgid=msgid, msg=line[off:].strip())
else:
self.msgReceived(type=mt, msg=line.strip())
示例14: cont
def cont(self, _=None):
while self.waiting:
try:
msg = self.waiting.pop(0)
log("fs20",DEBUG,msg)
d = self._dataReceived(msg)
except Exception as e:
fix_exception(e)
process_failure(e)
else:
if d:
d.addCallback(self.cont)
return
self.waiting = None
self._start_timer()
示例15: do_pre
def do_pre(self):
self.waiter = None
if self.running != "next" or self.slotter is not None:
log(ERROR,"timeslot error pre",self.running,*self.name)
return
if self.next is None:
self.next = now()
self.last = self.next
self.running = "during"
simple_event("timeslot","begin",*self.name, deprecated=True)
simple_event("timeslot","state",*self.name, state="begin")
self.next += dt.timedelta(0,self.duration)
self.slotter = callLater(False,self.next, self.do_post)