clan-app: fix logging error
on closing the logging file descriptor some parts of the program still had the old reference. This will replace the old fd with stderr to fix errors raised
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
@@ -91,12 +93,18 @@ class LoggingMiddleware(Middleware):
|
||||
exc_val: BaseException | None,
|
||||
exc_tb: types.TracebackType | None,
|
||||
) -> None:
|
||||
orig_stderr = None
|
||||
if self.handler:
|
||||
self.handler.root_logger.removeHandler(self.handler.new_handler)
|
||||
self.handler.new_handler.close()
|
||||
if self.original_ctx:
|
||||
set_async_ctx(self.original_ctx)
|
||||
orig_stderr = self.original_ctx.stderr
|
||||
if self.log_f:
|
||||
# Replace the file descriptor instead of closing it
|
||||
stderr = orig_stderr or sys.stderr
|
||||
new_fd = stderr.fileno()
|
||||
os.dup2(self.log_f.fileno(), new_fd)
|
||||
self.log_f.close()
|
||||
|
||||
# Register the logging context manager
|
||||
|
||||
Reference in New Issue
Block a user