|
31 | 31 | License: MIT
|
32 | 32 | """
|
33 | 33 | import logging
|
34 |
| -import os |
35 |
| -import time |
36 | 34 | from pathlib import Path
|
37 | 35 | from uuid import uuid4
|
38 | 36 |
|
@@ -215,43 +213,9 @@ def emit(self, record):
|
215 | 213 | logging.getLogger().setLevel(logging.NOTSET)
|
216 | 214 |
|
217 | 215 |
|
218 |
| - class ResilientFileSink: |
219 |
| - def __init__(self, path, retry_count=5, retry_delay=1): |
220 |
| - self.path = path |
221 |
| - self.retry_count = retry_count |
222 |
| - self.retry_delay = retry_delay |
223 |
| - # Ensure the directory exists |
224 |
| - os.makedirs(os.path.dirname(path), exist_ok=True) |
225 |
| - |
226 |
| - def __call__(self, message): # pragma: no cover |
227 |
| - attempt = 0 |
228 |
| - while attempt < self.retry_count: |
229 |
| - try: |
230 |
| - # Open the file in append mode and write the message |
231 |
| - with open(self.path, 'a') as file: |
232 |
| - file.write(message) |
233 |
| - break # Exit the loop if write succeeds |
234 |
| - except Exception as e: |
235 |
| - attempt += 1 |
236 |
| - time.sleep(self.retry_delay) |
237 |
| - if attempt == self.retry_count: |
238 |
| - print(f"Failed to log message after {self.retry_count} attempts: {e}") |
239 |
| - |
240 |
| - |
241 |
| - if file_sink: |
242 |
| - # Create an instance of ResilientFileSink if file_sink is True |
243 |
| - resilient_sink = ResilientFileSink(str(log_path)) |
244 |
| - |
245 |
| - # Append the ResilientFileSink instance to the handlers list |
246 |
| - basic_config_handlers.append(resilient_sink) |
247 |
| - |
248 | 216 | if intercept_standard_logging:
|
249 | 217 | # Append an InterceptHandler instance to the handlers list if intercept_standard_logging is True
|
250 | 218 | basic_config_handlers.append(InterceptHandler())
|
251 | 219 |
|
252 |
| - if len(basic_config_handlers) > 0: |
253 |
| - # Configure the root logger if there are any handlers specified |
254 |
| - logging.basicConfig(handlers=basic_config_handlers, level=logging_level.upper()) |
255 |
| - |
256 | 220 | if len(basic_config_handlers) > 0:
|
257 | 221 | logging.basicConfig(handlers=basic_config_handlers, level=logging_level.upper())
|
0 commit comments