import logging
import time

# Configure logging (consider moving to a dedicated logging setup file)
logger = logging.getLogger(__name__)

class DynamicAdjuster:
    def __init__(self, initial_threshold, scaling_factor, cpu_utilization_provider):
        self.threshold = initial_threshold
        self.scaling_factor = scaling_factor
        self.cpu_utilization_provider = cpu_utilization_provider

    def adjust_threshold(self):
        cpu_utilization = self.cpu_utilization_provider()
        original_threshold = self.threshold

        # Adjust the threshold based on CPU utilization
        self.threshold *= (1 + self.scaling_factor * (cpu_utilization - 0.5))
        self.threshold = max(0, self.threshold)  # Ensure threshold doesn't go negative

        # Log the threshold adjustment
        log_data = {
            'timestamp': time.time(),
            'original_threshold': original_threshold,
            'cpu_utilization': cpu_utilization,
            'scaling_factor': self.scaling_factor,
            'new_threshold': self.threshold
        }

        logger.info("Threshold adjusted", extra=log_data)

        return self.threshold

    def get_threshold(self):
        return self.threshold

# Example CPU utilization provider (replace with actual implementation)
def example_cpu_utilization_provider():
    # Simulate CPU utilization between 0 and 1
    return 0.6

if __name__ == '__main__':
    # Basic test
    logging.basicConfig(level=logging.INFO) #Configure basic logging for testing
    adjuster = DynamicAdjuster(initial_threshold=100, scaling_factor=0.1, cpu_utilization_provider=example_cpu_utilization_provider)
    print(f"Initial Threshold: {adjuster.get_threshold()}")
    new_threshold = adjuster.adjust_threshold()
    print(f"New Threshold: {new_threshold}")
