|
1 | | -"""Logging Configurator for aca-py agent.""" |
| 1 | +"""Logging Configurator for tails server.""" |
2 | 2 |
|
3 | 3 | import io |
4 | 4 | import logging |
5 | 5 | from importlib import resources |
6 | | -from logging.config import ( |
7 | | - dictConfigClass, |
8 | | -) |
| 6 | +from logging.config import dictConfigClass |
9 | 7 | from typing import Optional |
10 | 8 |
|
11 | 9 | import yaml |
@@ -53,60 +51,37 @@ class LoggingConfigurator: |
53 | 51 |
|
54 | 52 | @classmethod |
55 | 53 | def configure( |
56 | | - cls, |
57 | | - log_config_path: Optional[str] = None, |
58 | | - log_level: Optional[str] = None, |
59 | | - log_file: Optional[str] = None, |
| 54 | + cls, log_config_path: Optional[str] = None, log_level: Optional[str] = None |
60 | 55 | ): |
61 | 56 | """Configure logger. |
62 | 57 |
|
63 | 58 | :param logging_config_path: str: (Default value = None) Optional path to |
64 | 59 | custom logging config |
65 | 60 |
|
66 | 61 | :param log_level: str: (Default value = None) |
67 | | -
|
68 | | - :param log_file: str: (Default value = None) Optional file name to write logs to |
69 | 62 | """ |
70 | 63 |
|
71 | | - write_to_log_file = log_file is not None or log_file == "" |
72 | | - |
73 | | - # This is a check that requires a log file path to be provided if |
74 | | - # --log-file is specified on startup and a config file is not. |
75 | | - if not log_config_path and write_to_log_file and not log_file: |
76 | | - raise ValueError( |
77 | | - "log_file (--log-file) must be provided in single-tenant mode " |
78 | | - "using the default config since a log file path is not set." |
79 | | - ) |
80 | | - |
81 | | - cls._configure_logging( |
82 | | - log_config_path=log_config_path, |
83 | | - log_level=log_level, |
84 | | - log_file=log_file, |
85 | | - ) |
| 64 | + cls._configure_logging(log_config_path=log_config_path, log_level=log_level) |
86 | 65 |
|
87 | 66 | @classmethod |
88 | | - def _configure_logging(cls, log_config_path, log_level, log_file): |
| 67 | + def _configure_logging(cls, log_config_path, log_level): |
89 | 68 | # Setup log config and log file if provided |
90 | | - cls._setup_log_config_file(log_config_path, log_file) |
91 | | - |
92 | | - # Set custom file handler |
93 | | - if log_file: |
94 | | - logging.root.handlers.append(logging.FileHandler(log_file, encoding="utf-8")) |
| 69 | + cls._setup_log_config_file(log_config_path) |
95 | 70 |
|
96 | 71 | # Set custom log level |
97 | 72 | if log_level: |
98 | 73 | logging.root.setLevel(log_level.upper()) |
99 | 74 |
|
100 | 75 | @classmethod |
101 | | - def _setup_log_config_file(cls, log_config_path, log_file): |
| 76 | + def _setup_log_config_file(cls, log_config_path): |
102 | 77 | log_config, is_dict_config = cls._load_log_config(log_config_path) |
103 | 78 |
|
104 | 79 | # Setup config |
105 | 80 | if not log_config: |
106 | 81 | logging.basicConfig(level=logging.WARNING) |
107 | 82 | logging.root.warning(f"Logging config file not found: {log_config_path}") |
108 | 83 | elif is_dict_config: |
109 | | - dictConfig(log_config, new_file_path=log_file or None) |
| 84 | + dictConfig(log_config) |
110 | 85 |
|
111 | 86 | @classmethod |
112 | 87 | def _load_log_config(cls, log_config_path): |
|
0 commit comments