Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/mx_bluesky/common/utils/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import multiprocessing
from logging.handlers import TimedRotatingFileHandler
from os import environ
from pathlib import Path
Expand Down Expand Up @@ -90,10 +91,19 @@ def do_default_logging_setup(
graylog_port: int,
dev_mode: bool = False,
integrate_all_logs: bool = True,
process_name: str | None = None,
):
"""Configures dodal logger so that separate debug and info log files are created,
info logs are sent to Graylog, info logs are streamed to sys.sterr, and logs from ophyd
and bluesky and ophyd-async are optionally included."""
and bluesky and ophyd-async are optionally included.
Args:
file_name: Name of the log file for file-based logging
graylog_port: Port number for graylog
dev_mode (bool): True if we should not log to production graylog
integrate_all_logs (bool): True (the default) to include ophyd-async, bluesky logs in the parent dodal logger
process_name (str): Set the process name for LogRecord objects for inclusion in graylog."""
if process_name:
multiprocessing.current_process().name = process_name
logging_path, debug_logging_path = _get_logging_dirs(dev_mode)
handlers = set_up_all_logging_handlers(
DODAL_LOGGER,
Expand Down
5 changes: 4 additions & 1 deletion src/mx_bluesky/hyperion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@


def initialise_globals(args: HyperionArgs):
"""Do all early main low-level application initialisation."""
"""Do all early main low-level application initialization."""
do_default_logging_setup(
CONST.SUPERVISOR_LOG_FILE_NAME
if args.mode == HyperionMode.SUPERVISOR
else CONST.LOG_FILE_NAME,
CONST.GRAYLOG_PORT,
dev_mode=args.dev_mode,
process_name="hyperion-supervisor"
if args.mode == HyperionMode.SUPERVISOR
else "hyperion",
)
LOGGER.info(f"Hyperion launched with args:{argv}")
alerting.set_alerting_service(LoggingAlertService(CONST.GRAYLOG_STREAM_ID))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import multiprocessing
import os
from abc import abstractmethod
from collections.abc import Callable
Expand Down Expand Up @@ -122,6 +123,7 @@ def setup_callbacks() -> list[CallbackBase]:


def setup_logging(dev_mode: bool):
multiprocessing.current_process().name = "hyperion-callbacks"
for logger, filename in [
(ISPYB_ZOCALO_CALLBACK_LOGGER, "hyperion_ispyb_callback.log"),
(NEXUS_LOGGER, "hyperion_nexus_callback.log"),
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/hyperion/test_main_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_initialise_configures_logging(
initialise_globals(args)

mock_logging_setup.assert_called_once_with(
CONST.LOG_FILE_NAME, CONST.GRAYLOG_PORT, dev_mode=True
CONST.LOG_FILE_NAME, CONST.GRAYLOG_PORT, dev_mode=True, process_name="hyperion"
)


Expand Down Expand Up @@ -131,7 +131,7 @@ def test_hyperion_in_udc_mode_starts_logging(
main()

mock_do_default_logging_setup.assert_called_once_with(
CONST.LOG_FILE_NAME, CONST.GRAYLOG_PORT, dev_mode=False
CONST.LOG_FILE_NAME, CONST.GRAYLOG_PORT, dev_mode=False, process_name="hyperion"
)


Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading