Skip to content

Commit 4958390

Browse files
committed
Fix logs not propagated to azure
1 parent ca1c51f commit 4958390

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/ert/services/_storage_main.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
from opentelemetry.trace.span import Span
2828

29+
DARK_STORAGE_APP = "ert.dark_storage.app:app"
30+
2931

3032
class Server(uvicorn.Server):
3133
def __init__(
@@ -84,7 +86,7 @@ def _create_connection_info(sock: socket.socket, authtoken: str) -> Dict[str, An
8486

8587
return connection_info
8688

87-
def run_server(args: Optional[argparse.Namespace] = None, debug: bool = False) -> None:
89+
def run_server(args: Optional[argparse.Namespace] = None, debug: bool = False, uvicorn_config = None) -> None:
8890
trace_id = get_trace_id()
8991
if args is None:
9092
args = parse_args()
@@ -106,7 +108,7 @@ def run_server(args: Optional[argparse.Namespace] = None, debug: bool = False) -
106108
# Appropriated from uvicorn.main:run
107109
os.environ["ERT_STORAGE_NO_TOKEN"] = "1"
108110
os.environ["ERT_STORAGE_ENS_PATH"] = os.path.abspath(args.project)
109-
config = uvicorn.Config("ert.dark_storage.app:app", **config_args)
111+
config = uvicorn.Config(DARK_STORAGE_APP, **config_args) if uvicorn_config is None else uvicorn_config #uvicorn.Config() resets the logging config (overriding additional handlers added to loggers like e.g. the ert_azurelogger handler added through the pluggin system
110112
server = Server(config, json.dumps(connection_info))
111113

112114
logger = logging.getLogger("ert.shared.storage.info")
@@ -150,12 +152,18 @@ def check_parent_alive() -> bool:
150152

151153

152154
def main():
155+
args = parse_args()
156+
config_args: Dict[str, Any] = {}
153157
with open(STORAGE_LOG_CONFIG, encoding="utf-8") as conf_file:
154158
logging_conf = yaml.safe_load(conf_file)
155159
logging.config.dictConfig(logging_conf)
160+
config_args.update(log_config=logging_conf)
156161
warnings.filterwarnings("ignore", category=DeprecationWarning)
157-
uvicorn.config.LOGGING_CONFIG.clear()
158-
uvicorn.config.LOGGING_CONFIG.update(logging_conf)
162+
163+
if args.debug:
164+
config_args.update(reload=True, reload_dirs=[os.path.dirname(ert_shared_path)])
165+
uvicorn_config = uvicorn.Config(DARK_STORAGE_APP, **config_args) # Need to run uvicorn.Config before entering the ErtPluginContext because uvicorn.Config overrides the configuration of existing loggers, thus removing log handlers added by ErtPluginContext
166+
159167
_stopped = threading.Event()
160168
terminate_on_parent_death_thread = threading.Thread(
161169
target=terminate_on_parent_death, args=[_stopped, 1.0]
@@ -166,7 +174,7 @@ def main():
166174
try:
167175
current_span = trace.get_current_span()
168176
print(f"Opertation ID: {get_trace_id()}")
169-
run_server(debug=False)
177+
run_server(args, debug=False, uvicorn_config = uvicorn_config)
170178
except BaseException as err:
171179
print(f"Stopped with exception {err}")
172180
finally:

0 commit comments

Comments
 (0)