Skip to content

Commit

Permalink
circular loop fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosalmi committed Feb 1, 2025
1 parent d2db7c9 commit 7f3d868
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 0 additions & 4 deletions lxc_autoscale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any, Dict, List, Set, Union

import yaml
from logging_setup import setup_logging # Import the logging setup function

CONFIG_FILE = "/etc/lxc_autoscale/lxc_autoscale.yaml"

Expand All @@ -25,9 +24,6 @@ def load_tier_configurations() -> Dict[str, Dict[str, Any]]:
"""Load and validate tier configurations."""
tier_configs: Dict[str, Dict[str, Any]] = {}

# Setup logging based on the configuration
setup_logging()

for section, values in config.items():
if section.startswith('TIER_'):
tier_name = section[5:]
Expand Down
8 changes: 5 additions & 3 deletions lxc_autoscale/logging_setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import logging # Import the logging module to handle logging throughout the application
import os # Import os module to handle directory operations
from config import get_config_value # Import the get_config_value function to retrieve configuration settings

# Retrieve the log file path from the configuration
LOG_FILE = get_config_value('DEFAULT', 'log_file', '/var/log/lxc_autoscale.log')
# Removed: from config import get_config_value and global LOG_FILE assignment

def setup_logging():
"""
Expand All @@ -13,6 +11,10 @@ def setup_logging():
Log messages will include timestamps and the severity level of the message.
"""

# Lazy import to break circular dependency
from config import get_config_value
LOG_FILE = get_config_value('DEFAULT', 'log_file', '/var/log/lxc_autoscale.log')

# Ensure the directory for the log file exists
log_dir = os.path.dirname(LOG_FILE)
if not os.path.exists(log_dir):
Expand Down

0 comments on commit 7f3d868

Please sign in to comment.