import os
import logging

def setup_file_logger(log_dir="log", log_file="blackbox.log"):
    os.makedirs(log_dir, exist_ok=True)
    log_path = os.path.join(log_dir, log_file)

    logger = logging.getLogger("blackbox_file_logger")
    logger.setLevel(logging.INFO)

    if not logger.hasHandlers():
        handler = logging.FileHandler(log_path)
        formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # Set permissions for the log file
    try:
        os.chmod(log_path, 0o664)
    except OSError as e:
        print(f"Error setting permissions: {e}")

    return logger