Spaces:
Runtime error
Runtime error
File size: 2,053 Bytes
bb59984 d224e77 bb59984 eab8432 bb59984 950de85 bb59984 eab8432 bb59984 bbe344e bb59984 bbe344e bb59984 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import logging
import logging.config
from pathlib import Path
import os
import yaml
# from dotenv import find_dotenv, load_dotenv
logger = logging.getLogger(__name__)
open_api_key = os.getenv("COMET_API_KEY")
open_api_key = os.getenv("COMET_WORKSPACE")
open_api_key = os.getenv("COMET_PROJECT_NAME")
open_api_key = os.getenv("QDRANT_URL")
open_api_key = os.getenv("QDRANT_API_KEY")
def initialize(logging_config_path: str = "logging.yaml"):
"""
Initializes the logger and environment variables.
Args:
logging_config_path (str): The path to the logging configuration file. Defaults to "logging.yaml".
env_file_path (str): The path to the environment variables file. Defaults to ".env".
"""
logger.info("Initializing logger...")
try:
initialize_logger(config_path=logging_config_path)
except FileNotFoundError:
logger.warning(
f"No logging configuration file found at: {logging_config_path}. Setting logging level to INFO."
)
logging.basicConfig(level=logging.INFO)
"""
logger.info("Initializing env vars...")
if env_file_path is None:
env_file_path = find_dotenv(raise_error_if_not_found=True, usecwd=False)
logger.info(f"Loading environment variables from: {env_file_path}")
found_env_file = load_dotenv(env_file_path, verbose=True, override=True)
if found_env_file is False:
raise RuntimeError(f"Could not find environment file at: {env_file_path}")
"""
def initialize_logger(
config_path: str = "logging.yaml", logs_dir_name: str = "logs"
) -> logging.Logger:
"""Initialize logger from a YAML config file."""
# Create logs directory.
config_path_parent = Path(config_path).parent
logs_dir = config_path_parent / logs_dir_name
logs_dir.mkdir(parents=True, exist_ok=True)
with open(config_path, "rt") as f:
config = yaml.safe_load(f.read())
# Make sure that existing logger will still work.
config["disable_existing_loggers"] = False
logging.config.dictConfig(config)
|