|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | from dataclasses import dataclass, field |
5 | | -from enum import Enum |
6 | 5 | from pathlib import Path |
7 | 6 | from typing import Optional, Union |
8 | 7 |
|
9 | 8 | import yaml |
10 | 9 |
|
11 | | -from .exceptions import ConfigurationError |
12 | | -from .prompts import PromptConfig |
| 10 | +from codegate.codegate_logging import setup_logging, LogFormat, LogLevel |
| 11 | +from codegate.exceptions import ConfigurationError |
| 12 | +from codegate.prompts import PromptConfig |
13 | 13 |
|
14 | | - |
15 | | -class LogLevel(str, Enum): |
16 | | - """Valid log levels.""" |
17 | | - |
18 | | - ERROR = "ERROR" |
19 | | - WARNING = "WARNING" |
20 | | - INFO = "INFO" |
21 | | - DEBUG = "DEBUG" |
22 | | - |
23 | | - @classmethod |
24 | | - def _missing_(cls, value: str) -> Optional["LogLevel"]: |
25 | | - """Handle case-insensitive lookup of enum values.""" |
26 | | - try: |
27 | | - # Convert to uppercase and look up directly |
28 | | - return cls[value.upper()] |
29 | | - except (KeyError, AttributeError): |
30 | | - raise ValueError( |
31 | | - f"'{value}' is not a valid LogLevel. " |
32 | | - f"Valid levels are: {', '.join(level.value for level in cls)}" |
33 | | - ) |
34 | | - |
35 | | - |
36 | | -class LogFormat(str, Enum): |
37 | | - """Valid log formats.""" |
38 | | - |
39 | | - JSON = "JSON" |
40 | | - TEXT = "TEXT" |
41 | | - |
42 | | - @classmethod |
43 | | - def _missing_(cls, value: str) -> Optional["LogFormat"]: |
44 | | - """Handle case-insensitive lookup of enum values.""" |
45 | | - try: |
46 | | - # Convert to uppercase and look up directly |
47 | | - return cls[value.upper()] |
48 | | - except (KeyError, AttributeError): |
49 | | - raise ValueError( |
50 | | - f"'{value}' is not a valid LogFormat. " |
51 | | - f"Valid formats are: {', '.join(format.value for format in cls)}" |
52 | | - ) |
| 14 | +logger = setup_logging() |
53 | 15 |
|
54 | 16 |
|
55 | 17 | @dataclass |
@@ -219,9 +181,7 @@ def load( |
219 | 181 | config = cls.from_file(config_path) |
220 | 182 | except ConfigurationError as e: |
221 | 183 | # Log warning but continue with defaults |
222 | | - import logging |
223 | | - |
224 | | - logging.warning(f"Failed to load config file: {e}") |
| 184 | + logger.warning(f"Failed to load config file: {e}") |
225 | 185 |
|
226 | 186 | # Override with environment variables |
227 | 187 | env_config = cls.from_env() |
|
0 commit comments