Ejemplo n.º 1
0
	def report(self, verbose=False):
		try:
			yield  u"END: "+six.text_type(Name(self.name[1:]))
		except Exception as e:
			fix_exception(e)
			print("LOGGER CRASH 4", file=sys.stderr)
			print_exception(e,file=sys.stderr)
			yield  "END: REPORT_ERROR: "+repr(self.name[1:])
Ejemplo n.º 2
0
 def report(self, verbose=False):
     try:
         yield u"END: " + six.text_type(Name(self.name[1:]))
     except Exception as e:
         fix_exception(e)
         print("LOGGER CRASH 4", file=sys.stderr)
         print_exception(e, file=sys.stderr)
         yield "END: REPORT_ERROR: " + repr(self.name[1:])
Ejemplo n.º 3
0
	def process(self, event, **k):
		from moat.collect import collections
		super(Shutdown_Collections,self).process(**k)

		for w in sorted(collections.values(),key=lambda x:x.prio):
			if not w.can_do("del"):
				continue
			for d in w.values():
				try:
					d.delete(event.ctx)
				except Exception as ex:
					fix_exception(ex)
					print_exception(ex)
Ejemplo n.º 4
0
    def process(self, event, **k):
        from moat.collect import collections
        super(Shutdown_Collections, self).process(**k)

        for w in sorted(collections.values(), key=lambda x: x.prio):
            if not w.can_do("del"):
                continue
            for d in w.values():
                try:
                    d.delete(event.ctx)
                except Exception as ex:
                    fix_exception(ex)
                    print_exception(ex)
Ejemplo n.º 5
0
 def _main():
     global ht
     parse_ctx = Context(filename=name)
     #parse_ctx.logger=parse_logger
     try:
         parse(input, interpreter(Context(out=logwrite(logger))), parse_ctx)
     except Exception as e:
         fix_exception(e)
         print_exception(e, file=sys.stderr)
     finally:
         shut_down()
         if ht is not None:
             ht.try_exit()
             ht = None
Ejemplo n.º 6
0
	def _main():
		global ht
		parse_ctx = Context(filename=name)
		#parse_ctx.logger=parse_logger
		try:
			parse(input, interpreter(Context(out=logwrite(logger))),parse_ctx)
		except Exception as e:
			fix_exception(e)
			print_exception(e,file=sys.stderr)
		finally:
			shut_down()
			if ht is not None:
				ht.try_exit()
				ht = None
Ejemplo n.º 7
0
def log(level, *a):
    """\
		Run through all loggers. If one of then throws an exception,
		drop the logger and process it.

		Special feature: You can pass a subsystem name as the very first
		argument. Logging for that subsystem can be enabled by
		log_level(subsys_name, LEVEL).
		"""
    try:
        level = LogNames[level]
    except KeyError:
        try:
            lim = levels[level]
        except KeyError:
            lim = TRACE if TESTING else INFO
        if isinstance(a[0], six.integer_types
                      ) and TRACE <= a[0] <= PANIC or a[0] in LogLevels:
            b = level
            level = a[0]
            level = LogLevels.get(level, level)
            if lim > level:
                return
            a = (b, ) + a[1:]
            level = LogNames[level]

    logger.log(getattr(logging, level, logging.DEBUG), "%s",
               " ".join(str(x) for x in a))

    exc = []
    for l in list(Loggers.values()):
        if not l.ready:
            continue
        try:
            l.log(level, *a)
        except Exception as e:
            fix_exception(e)
            print("LOGGER CRASH 0", file=sys.stderr)
            print_exception(e, file=sys.stderr)
            l.delete()
            exc.append(sys.exc_info())
    if exc:
        for e in exc:
            log_exc(msg="Logging error", err=e)
Ejemplo n.º 8
0
def log(level, *a):
	"""\
		Run through all loggers. If one of then throws an exception,
		drop the logger and process it.

		Special feature: You can pass a subsystem name as the very first
		argument. Logging for that subsystem can be enabled by
		log_level(subsys_name, LEVEL).
		"""
	try:
		level = LogNames[level]
	except KeyError: 
		try:
			lim = levels[level]
		except KeyError:
			lim = TRACE if TESTING else INFO
		if isinstance(a[0],six.integer_types) and TRACE<=a[0]<=PANIC or a[0] in LogLevels:
			b = level
			level = a[0]
			level = LogLevels.get(level,level)
			if lim > level:
				return
			a = (b,)+a[1:]
			level = LogNames[level]
			
	logger.log(getattr(logging,level,logging.DEBUG),"%s"," ".join(str(x) for x in a))

	exc = []
	for l in list(Loggers.values()):
		if not l.ready:
			continue
		try:
			l.log(level, *a)
		except Exception as e:
			fix_exception(e)
			print("LOGGER CRASH 0", file=sys.stderr)
			print_exception(e,file=sys.stderr)
			l.delete()
			exc.append(sys.exc_info())
	if exc:
		for e in exc:
			log_exc(msg="Logging error", err=e)
Ejemplo n.º 9
0
    def process(self, event=None, **k):
        """\
			Run through all loggers. If one of then throws an exception,
			drop the logger and process it.
			"""
        super(LogWorker, self).process(event=event, **k)
        exc = []
        level = k.get("level", TRACE)
        try:
            if event is None:
                loglevel = NONE
            else:
                loglevel = event.loglevel or TRACE
            if loglevel == NONE or loglevel > level:
                return
        except AttributeError:
            pass
        if levels.get("event", TRACE) > level:
            return

        subsys = k.get("subsys", None)
        if subsys is not None:
            lim = levels.get(subsys, NONE)
            if lim == NONE or lim > TRACE:
                return

        for l in list(Loggers.values()):
            if not l.ready:
                continue
            try:
                l.log_event(event=event, level=level)
            except Exception as e:
                fix_exception(e)
                print("LOGGER CRASH 1", file=sys.stderr)
                print_exception(e, file=sys.stderr)
                l.end_logging()
                exc.append(sys.exc_info())
        if exc:
            for e in exc:
                log_exc(msg="Logging error", err=e)
Ejemplo n.º 10
0
	def process(self,event=None,**k):
		"""\
			Run through all loggers. If one of then throws an exception,
			drop the logger and process it.
			"""
		super(LogWorker,self).process(event=event,**k)
		exc = []
		level = k.get("level",TRACE)
		try:
			if event is None:
				loglevel = NONE
			else:
				loglevel = event.loglevel or TRACE
			if loglevel == NONE or loglevel > level:
				return
		except AttributeError:
			pass
		if levels.get("event",TRACE) > level:
			return

		subsys = k.get("subsys",None)
		if subsys is not None:
			lim = levels.get(subsys,NONE)
			if lim == NONE or lim > TRACE:
				return

		for l in list(Loggers.values()):
			if not l.ready:
				continue
			try:
				l.log_event(event=event,level=level)
			except Exception as e:
				fix_exception(e)
				print("LOGGER CRASH 1", file=sys.stderr)
				print_exception(e,file=sys.stderr)
				l.end_logging()
				exc.append(sys.exc_info())
		if exc:
			for e in exc:
				log_exc(msg="Logging error", err=e)
Ejemplo n.º 11
0
def log_exc(msg=None, err=None, level=ERROR):
    level = LogNames.get(level, level)

    for l in list(Loggers.values()):
        if not l.ready:
            continue
        if msg:
            try:
                l.log(level, msg)
            except Exception as e:
                fix_exception(e)
                print("LOGGER CRASH 2", file=sys.stderr)
                print_exception(e, file=sys.stderr)
                l.end_logging()
                log_exc(msg="Logger removed", err=e)
        try:
            l.log_failure(err, level=LogLevels[level])
        except Exception as e:
            fix_exception(e)
            print("LOGGER CRASH 3", file=sys.stderr)
            print_exception(e, file=sys.stderr)
            l.end_logging()
            log_exc(msg="Logger removed", err=e)
Ejemplo n.º 12
0
def log_exc(msg=None, err=None, level=ERROR):
	level = LogNames.get(level,level)

	for l in list(Loggers.values()):
		if not l.ready:
			continue
		if msg:
			try:
				l.log(level,msg)
			except Exception as e:
				fix_exception(e)
				print("LOGGER CRASH 2", file=sys.stderr)
				print_exception(e,file=sys.stderr)
				l.end_logging()
				log_exc(msg="Logger removed",err=e)
		try:
			l.log_failure(err, level=LogLevels[level])
		except Exception as e:
			fix_exception(e)
			print("LOGGER CRASH 3", file=sys.stderr)
			print_exception(e,file=sys.stderr)
			l.end_logging()
			log_exc(msg="Logger removed",err=e)
Ejemplo n.º 13
0
Archivo: data.py Proyecto: M-o-a-T/moat
	def run(self,ctx,**k):

		def out_one(c):
			for p,t in flatten((c,)):
				if isinstance(t,datetime):
					if TESTING and t.year != 2003:
						t = "%s" % (humandelta(t-now(t.year != 2003)),)
					else:
						t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
					if TESTING:
						lim = 3
					else:
						lim = 4
					ti = t.rfind('.')
					if ti>0 and len(t)-ti>lim and len(t)-ti<lim+6: # limit to msec
						t = t[:ti+lim]+")"

				elif isinstance(t,float):
					ft=float("%.4f"%t)
					if abs(ft-t)<0.00000001:
						t=ft
				print(p+u": "+six.text_type(t), file=self.ctx.out)

		event = self.params(ctx)
		c = get_collect(event, allow_collection=True)

		try:
			if c is None:
				for m in all_collect(skip=False):
					print(" ".join(m.name), file=self.ctx.out)
			elif isinstance(c,Collection):
				if event[-1] == "*":
					for m in c.items():
						print("* %s :: %s" % (n,m), file=self.ctx.out)
						out_one(m)
					return
				for n,m in c.items():
					try:
						m = m.info
					except AttributeError:
						m = m.name
					else:
						if callable(m):
							m = m()
						if isinstance(m,six.string_types):
							m = m.split("\n")[0].strip()

					if isinstance(n,Name):
						n = u" ".join(six.text_type(x) for x in n)
					if m is not None:
						print(u"%s :: %s" % (n,m), file=self.ctx.out)
					else:
						print(u"%s" % (n,), file=self.ctx.out)
			else:
				out_one(c)

		except Exception as e:
			fix_exception(e)
			print("* ERROR *",repr(e), file=self.ctx.out)
			print_exception(e,file=self.ctx.out)
		finally:
			print(".", file=self.ctx.out)
Ejemplo n.º 14
0
    def run(self, ctx, **k):
        def out_one(c):
            for p, t in flatten((c, )):
                if isinstance(t, datetime):
                    if TESTING and t.year != 2003:
                        t = "%s" % (humandelta(t - now(t.year != 2003)), )
                    else:
                        t = "%s (%s)" % (humandelta(t - now(t.year != 2003)),
                                         t)
                    if TESTING:
                        lim = 3
                    else:
                        lim = 4
                    ti = t.rfind('.')
                    if ti > 0 and len(t) - ti > lim and len(
                            t) - ti < lim + 6:  # limit to msec
                        t = t[:ti + lim] + ")"

                elif isinstance(t, float):
                    ft = float("%.4f" % t)
                    if abs(ft - t) < 0.00000001:
                        t = ft
                print(p + u": " + six.text_type(t), file=self.ctx.out)

        event = self.params(ctx)
        c = get_collect(event, allow_collection=True)

        try:
            if c is None:
                for m in all_collect(skip=False):
                    print(" ".join(m.name), file=self.ctx.out)
            elif isinstance(c, Collection):
                if event[-1] == "*":
                    for m in c.items():
                        print("* %s :: %s" % (n, m), file=self.ctx.out)
                        out_one(m)
                    return
                for n, m in c.items():
                    try:
                        m = m.info
                    except AttributeError:
                        m = m.name
                    else:
                        if callable(m):
                            m = m()
                        if isinstance(m, six.string_types):
                            m = m.split("\n")[0].strip()

                    if isinstance(n, Name):
                        n = u" ".join(six.text_type(x) for x in n)
                    if m is not None:
                        print(u"%s :: %s" % (n, m), file=self.ctx.out)
                    else:
                        print(u"%s" % (n, ), file=self.ctx.out)
            else:
                out_one(c)

        except Exception as e:
            fix_exception(e)
            print("* ERROR *", repr(e), file=self.ctx.out)
            print_exception(e, file=self.ctx.out)
        finally:
            print(".", file=self.ctx.out)