Esempio n. 1
0
async def get_logs(host):
    reader, writer = await asyncio.open_connection(host, 1380)
    writer.write(b"ARTIQ management\n")
    writer.write(struct.pack("B", Request.PullLog.value))
    await writer.drain()

    while True:
        length, = struct.unpack(">l", await reader.readexactly(4))
        log = await reader.readexactly(length)

        for line in log.decode("utf-8").splitlines():
            m = re.match(r"^\[.+?\] (TRACE|DEBUG| INFO| WARN|ERROR)\((.+?)\): (.+)$", line)
            if m.group(1) == 'TRACE':
                continue
            elif m.group(1) == 'DEBUG':
                level = logging.DEBUG
            elif m.group(1) == ' INFO':
                level = logging.INFO
            elif m.group(1) == ' WARN':
                level = logging.WARN
            elif m.group(1) == 'ERROR':
                level = logging.ERROR
            name = 'firmware.' + m.group(2).replace('::', '.')
            text = m.group(3)
            log_with_name(name, level, text)
Esempio n. 2
0
async def get_logs(host):
    reader, writer = await asyncio.open_connection(host, 1380)
    writer.write(b"ARTIQ management\n")
    writer.write(struct.pack("B", Request.PullLog.value))
    await writer.drain()

    while True:
        length, = struct.unpack(">l", await reader.readexactly(4))
        log = await reader.readexactly(length)

        for line in log.decode("utf-8").splitlines():
            m = re.match(
                r"^\[.+?\] (TRACE|DEBUG| INFO| WARN|ERROR)\((.+?)\): (.+)$",
                line)
            levelname = m.group(1)
            if levelname == 'TRACE':
                level = logging.TRACE
            elif levelname == 'DEBUG':
                level = logging.DEBUG
            elif levelname == ' INFO':
                level = logging.INFO
            elif levelname == ' WARN':
                level = logging.WARN
            elif levelname == 'ERROR':
                level = logging.ERROR
            name = 'firmware.' + m.group(2).replace('::', '.')
            text = m.group(3)
            log_with_name(name, level, text)
Esempio n. 3
0
 async def forward_logs(self, stream):
     source = "controller({})".format(self.name)
     while True:
         try:
             entry = (await stream.readline())
             if not entry:
                 break
             entry = entry[:-1]
             level, name, message = parse_log_message(entry.decode())
             log_with_name(name, level, message, extra={"source": source})
         except:
             logger.debug("exception in log forwarding", exc_info=True)
             break
     logger.debug("stopped log forwarding of stream %s of %s", stream,
                  self.name)
Esempio n. 4
0
 async def forward_logs(self, stream):
     source = "controller({})".format(self.name)
     while True:
         try:
             entry = (await stream.readline())
             if not entry:
                 break
             entry = entry[:-1]
             level, name, message = parse_log_message(entry.decode())
             log_with_name(name, level, message, extra={"source": source})
         except:
             logger.debug("exception in log forwarding", exc_info=True)
             break
     logger.debug("stopped log forwarding of stream %s of %s",
         stream, self.name)
Esempio n. 5
0
def log_worker(rid, message):
    level, name, message = parse_log_message(message)
    log_with_name(name,
                  level,
                  message,
                  extra={"source": "worker({})".format(rid)})
Esempio n. 6
0
async def get_logs_sim(host):
    while True:
        await asyncio.sleep(2)
        log_with_name("firmware.simulation", logging.INFO, "hello " + host)
Esempio n. 7
0
async def get_logs_sim(host):
    while True:
        await asyncio.sleep(2)
        log_with_name("firmware.simulation", logging.INFO, "hello " + host)
Esempio n. 8
0
def log_worker(rid, message):
    level, name, message = parse_log_message(message)
    log_with_name(name, level, message,
                  extra={"source": "worker({})".format(rid)})