Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
d-perl committed Mar 1, 2024
1 parent 53082b3 commit d36ecfa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hyperion/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def do_default_logging_setup(dev_mode=False):
)
integrate_bluesky_and_ophyd_logging(dodal_logger, handlers)
handlers["graylog_handler"].addFilter(dc_group_id_filter)
handlers["graylog_handler"].addFilter(dc_group_id_filter)
handlers["graylog_handler"].addFilter(run_uid_filter)


def _get_logging_dir() -> Path:
Expand Down
40 changes: 40 additions & 0 deletions tests/unit_tests/hyperion/test_log/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
from unittest.mock import MagicMock, patch

import pytest
from bluesky import plan_stubs as bps
from bluesky import preprocessors as bpp
from dodal.log import LOGGER as dodal_logger
from dodal.log import set_up_all_logging_handlers

from hyperion import log
from hyperion.external_interaction.callbacks.log_uid_tag_callback import (
LogUidTaggingCallback,
)
from hyperion.parameters.constants import SET_LOG_UID_TAG

from .conftest import _destroy_loggers

Expand Down Expand Up @@ -75,6 +81,40 @@ def test_messages_logged_from_dodal_and_hyperion_contain_dcgid(
assert all(dc_group_id_correct)


@pytest.mark.skip_log_setup
def test_messages_are_tagged_with_run_uid(clear_and_mock_loggers, RE):
_, mock_GELFTCPHandler_emit = clear_and_mock_loggers
log.do_default_logging_setup(dev_mode=True)

RE.subscribe(LogUidTaggingCallback())
test_run_uid = None

@bpp.run_decorator(
md={
SET_LOG_UID_TAG: True,
}
)
def test_plan():
yield from bps.sleep(0)
assert log.run_uid_filter.run_uid is not None
nonlocal test_run_uid
test_run_uid = log.run_uid_filter.run_uid
logger = log.LOGGER
logger.info("test_hyperion")
dodal_logger.info("test_dodal")
yield from bps.sleep(0)

assert log.run_uid_filter.run_uid is None
RE(test_plan())
assert log.run_uid_filter.run_uid is None

graylog_calls = mock_GELFTCPHandler_emit.mock_calls[5:-5]
assert len(graylog_calls) == 2

dc_group_id_correct = [c.args[0].run_uid == test_run_uid for c in graylog_calls]
assert all(dc_group_id_correct)


@pytest.mark.skip_log_setup
def test_messages_logged_from_dodal_and_hyperion_get_sent_to_graylog_and_file(
clear_and_mock_loggers,
Expand Down

0 comments on commit d36ecfa

Please sign in to comment.