Example #1
0
def run(log_name, path, debug=False, mail=None, timeout=0):
    """
    Run a subscriber and pass the messages to the logbook setup.
    Stays alive as long as the pubsub instance listen to something.

    :param log_name: the channel to listen to
    :param path: the path where the log files will be written
    :param debug: True if you want to save the debug messages too
    :param mail: Path to the config file for the mails

    """
    global pubsub
    global channel
    channel = log_name
    if use_tcp_socket:
        r = redis.StrictRedis(host=hostname, port=port)
    else:
        r = redis.StrictRedis(unix_socket_path=unix_socket)
    pubsub = r.pubsub()
    pubsub.psubscribe(channel + '.*')

    if timeout != 0:
        deadline = time.time() + timeout

    logger = Logger(channel)
    if mail is not None:
        mail_setup(mail)
    if os.path.exists(path) and not os.path.isdir(path):
        raise Exception(
            "The path you want to use to save the file is invalid (not a directory)."
        )
    if not os.path.exists(path):
        os.mkdir(path)
    with setup(channel, path, debug):
        while True:
            msg = pubsub.get_message()
            if msg:
                if msg['type'] == 'pmessage':
                    level = msg['channel'].decode('utf-8').split('.')[1]
                    message = msg['data']
                    try:
                        message = message.decode('utf-8')
                    except:
                        pass
                    logger.log(level, message)
            time.sleep(0.01)
            if timeout > 0:
                if time.time() >= deadline:
                    break
Example #2
0
def run(log_name, path, debug=False, mail=None, timeout=0):
    """
    Run a subscriber and pass the messages to the logbook setup.
    Stays alive as long as the pubsub instance listen to something.

    :param log_name: the channel to listen to
    :param path: the path where the log files will be written
    :param debug: True if you want to save the debug messages too
    :param mail: Path to the config file for the mails

    """
    global pubsub
    global channel
    channel = log_name
    if use_tcp_socket:
        r = redis.StrictRedis(host=hostname, port=port)
    else:
        r = redis.StrictRedis(unix_socket_path=unix_socket)
    pubsub = r.pubsub()
    pubsub.psubscribe(channel + ".*")

    if timeout != 0:
        deadline = time.time() + timeout

    logger = Logger(channel)
    if mail is not None:
        mail_setup(mail)
    if os.path.exists(path) and not os.path.isdir(path):
        raise Exception("The path you want to use to save the file is invalid (not a directory).")
    if not os.path.exists(path):
        os.mkdir(path)
    with setup(channel, path, debug):
        while True:
            msg = pubsub.get_message()
            if msg:
                if msg["type"] == "pmessage":
                    level = msg["channel"].decode("utf-8").split(".")[1]
                    message = msg["data"]
                    try:
                        message = message.decode("utf-8")
                    except:
                        pass
                    logger.log(level, message)
            time.sleep(0.01)
            if timeout > 0:
                if time.time() >= deadline:
                    break
Example #3
0
def run(log_name, path, debug=False, mail=None):
    """
    Run a subscriber and pass the messages to the logbook setup.
    Stays alive as long as the pubsub instance listen to something.

    :param log_name: the channel to listen to
    :param path: the path where the log files will be written
    :param debug: True if you want to save the debug messages too
    :param mail: Path to the config file for the mails

    """
    global pubsub
    global channel
    channel = log_name
    if use_tcp_socket:
        r = redis.StrictRedis(host=hostname, port=port)
    else:
        r = redis.StrictRedis(unix_socket_path=unix_socket)
    pubsub = r.pubsub()
    pubsub.psubscribe(channel + '.*')

    logger = Logger(channel)
    if mail is not None:
        mail_setup(mail)
    if os.path.exists(path) and not os.path.isdir(path):
        raise Exception("The path you want to use to save the file is invalid (not a directory).")
    if not os.path.exists(path):
        os.mkdir(path)
    with setup(channel, path, debug):
        for msg in pubsub.listen():
            if msg['type'] == 'pmessage':
                level = msg['channel'].split('.')[1]
                message = msg['data']
                try:
                    message = message.decode('utf-8')
                except:
                    pass
                logger.log(level, message)