Exemplo n.º 1
0
def _get_logger():
    process_id = os.getpid()
    
    client_logger = logging.getLogger('blacksheep.client')

    if __debug__:
        client_logger.setLevel(logging.DEBUG)
    else:
        client_logger.setLevel(logging.INFO)

    now = datetime.now()
    ts = now.strftime('%Y%m%d')
    hour_ts = now.strftime('%H%M%S')

    ensure_folder(f'logs/{ts}')

    max_bytes = 24 * 1024 * 1024

    file_handler = logging.handlers.RotatingFileHandler

    client_handler = file_handler(f'logs/{ts}/{hour_ts}-blacksheep-client-{process_id}.log',
                                  maxBytes=max_bytes,
                                  backupCount=5)
    client_handler.setLevel(logging.DEBUG)
    client_handler.setFormatter(logging.Formatter('%(levelname)s %(asctime)s @ BlackSheep.Client: %(message)s'))

    client_logger.addHandler(client_handler)

    return client_logger
Exemplo n.º 2
0
def _get_loggers():
    process_id = os.getpid()

    access_logger = logging.getLogger('blacksheep.server-access')
    app_logger = logging.getLogger('blacksheep.server')

    app_logger.setLevel(logging.INFO)
    access_logger.setLevel(logging.DEBUG)

    max_bytes = 24 * 1024 * 1024

    file_handler = logging.handlers.RotatingFileHandler

    now = datetime.now()
    ts = now.strftime('%Y%m%d')
    hour_ts = now.strftime('%H%M%S')

    ensure_folder(f'logs/{ts}')

    access_handler = file_handler(f'logs/{ts}/{hour_ts}-blacksheep-access-{process_id}.log',
                                  maxBytes=max_bytes,
                                  backupCount=5)

    app_handler = file_handler(f'logs/{ts}/{hour_ts}-blacksheep-{process_id}.log',
                               maxBytes=max_bytes,
                               backupCount=5)

    access_handler.setLevel(logging.DEBUG)
    app_handler.setLevel(logging.DEBUG)
    app_handler.setFormatter(logging.Formatter(
        '%(levelname)s @ %(asctime)s @ %(filename)s '
        '%(funcName)s %(lineno)d: %(message)s'))

    access_logger.addHandler(access_handler)
    app_logger.addHandler(app_handler)

    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    app_logger.addHandler(handler)
    access_logger.addHandler(handler)

    access_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))

    return access_logger, app_logger