From f87f908638eba9d6f3f87387378c488fa7e22e86 Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 09:50:29 +0100 Subject: [PATCH 01/12] Added document logging & unit tests --- .../callbacks/document_logger.py | 34 +++++++++++++++++++ src/ibex_bluesky_core/run_engine.py | 4 +++ tests/test_run_engine.py | 28 ++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/ibex_bluesky_core/callbacks/document_logger.py diff --git a/src/ibex_bluesky_core/callbacks/document_logger.py b/src/ibex_bluesky_core/callbacks/document_logger.py new file mode 100644 index 0000000..b910e2c --- /dev/null +++ b/src/ibex_bluesky_core/callbacks/document_logger.py @@ -0,0 +1,34 @@ +"""Logs all documents that the BlueSky run engine creates via a callback""" + +import os, json +from pathlib import Path + +DEFAULT_LOG_LOCATION = Path(os.path.join("C:\\","instrument","var","logs","bluesky","raw_documents")) + + +class DocLoggingCallback(): + + def __init__(self) -> None: + self.current_start_document = None + self.filename = None + + def __call__(self, name, document): + + if name == "start": + + DEFAULT_LOG_LOCATION.mkdir(parents=True, exist_ok=True) + + self.current_start_document = document["uid"] + self.filename = os.path.join(DEFAULT_LOG_LOCATION, f"{self.current_start_document}.log") + + assert self.current_start_document is not None, "Saw a non-start document before a start." + + to_write = { + "type": name, + "document": document + } + + with open(self.filename, 'a') as outfile: + outfile.write(f"{json.dumps(to_write)}\n") + + return 0 diff --git a/src/ibex_bluesky_core/run_engine.py b/src/ibex_bluesky_core/run_engine.py index 52e0d2b..a9c3370 100644 --- a/src/ibex_bluesky_core/run_engine.py +++ b/src/ibex_bluesky_core/run_engine.py @@ -6,6 +6,7 @@ from bluesky.run_engine import RunEngine from bluesky.utils import DuringTask +from ibex_bluesky_core.callbacks.document_logger import DocLoggingCallback __all__ = ["get_run_engine"] @@ -65,4 +66,7 @@ def get_run_engine() -> RunEngine: ) RE.record_interruptions = True + log_callback = DocLoggingCallback() + RE.subscribe(log_callback) # Uses ID = 0 for DocLoggingCallback + return RE diff --git a/tests/test_run_engine.py b/tests/test_run_engine.py index 99acb81..5334550 100644 --- a/tests/test_run_engine.py +++ b/tests/test_run_engine.py @@ -1,12 +1,15 @@ +import json +from pathlib import Path import threading from typing import Any, Generator -from unittest.mock import MagicMock +from unittest.mock import MagicMock, mock_open, patch import bluesky.plan_stubs as bps import pytest from bluesky.run_engine import RunEngine, RunEngineResult from bluesky.utils import Msg, RequestAbort, RequestStop, RunEngineInterrupted from ibex_bluesky_core.run_engine import _DuringTask, get_run_engine +import os @pytest.fixture @@ -139,3 +142,26 @@ def test_during_task_does_wait_with_small_timeout(): event.wait.assert_called_with(0.1) assert event.wait.call_count == 2 + +def test_run_engine_logs_all_documents(RE): + + m = mock_open() + filepath: str + DEFAULT_LOG_LOCATION = Path(os.path.join("C:\\","instrument","var","logs","bluesky","raw_documents")) + + def basic_plan() -> Generator[Msg, None, None]: + yield from bps.open_run() + yield from bps.close_run() + + with patch('ibex_bluesky_core.callbacks.document_logger.open', m): + result: RunEngineResult = RE(basic_plan()) + filepath = os.path.join(DEFAULT_LOG_LOCATION, f"{result.run_start_uids[0]}.log") + + for i in range (0,3): + assert m.call_args_list[i].args == (filepath, 'a') # Checks that the file is opened 3 times, for open, descriptor then stop + + handle = m() + document = json.loads(handle.write.mock_calls[-1].args[0]) + + assert document['document']['exit_status'] == "success" # In the stop document to be written, check that the run is successful with no interruptions + assert document['document']['num_events']['interruptions'] == 0 From 0ea446f41e1865c3cd904633c91f265f382b55cc Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 11:20:15 +0100 Subject: [PATCH 02/12] Ruff reformating & pyright corrections --- .../callbacks/document_logger.py | 39 ++++++++++++------- src/ibex_bluesky_core/run_engine.py | 3 +- tests/test_run_engine.py | 28 +++++++------ 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/ibex_bluesky_core/callbacks/document_logger.py b/src/ibex_bluesky_core/callbacks/document_logger.py index b910e2c..4472f0b 100644 --- a/src/ibex_bluesky_core/callbacks/document_logger.py +++ b/src/ibex_bluesky_core/callbacks/document_logger.py @@ -1,34 +1,45 @@ -"""Logs all documents that the BlueSky run engine creates via a callback""" +"""Logs all documents that the BlueSky run engine creates via a callback.""" -import os, json +import json +import os from pathlib import Path -DEFAULT_LOG_LOCATION = Path(os.path.join("C:\\","instrument","var","logs","bluesky","raw_documents")) +log_location = Path(os.path.join("C:\\", "instrument", "var", "logs", "bluesky", "raw_documents")) -class DocLoggingCallback(): +class DocLoggingCallback: + """ + Logs all documents under log_location, with the file name of their UID (.log). + """ def __init__(self) -> None: + """ + Initialises current_start_document and filename. + """ + self.current_start_document = None self.filename = None - def __call__(self, name, document): + def __call__(self, name: str, document: dict) -> int: + """ + Is called when a new document needs to be processed. Writes document to a file. - if name == "start": + Args: + name: The type of the document e.g start, event, stop + document: The contents of the docuement as a dictionary + """ - DEFAULT_LOG_LOCATION.mkdir(parents=True, exist_ok=True) + if name == "start": + log_location.mkdir(parents=True, exist_ok=True) self.current_start_document = document["uid"] - self.filename = os.path.join(DEFAULT_LOG_LOCATION, f"{self.current_start_document}.log") + self.filename: str = os.path.join(log_location, f"{self.current_start_document}.log") assert self.current_start_document is not None, "Saw a non-start document before a start." - - to_write = { - "type": name, - "document": document - } - with open(self.filename, 'a') as outfile: + to_write = {"type": name, "document": document} + + with open(self.filename, "a") as outfile: outfile.write(f"{json.dumps(to_write)}\n") return 0 diff --git a/src/ibex_bluesky_core/run_engine.py b/src/ibex_bluesky_core/run_engine.py index a9c3370..9915cc3 100644 --- a/src/ibex_bluesky_core/run_engine.py +++ b/src/ibex_bluesky_core/run_engine.py @@ -6,6 +6,7 @@ from bluesky.run_engine import RunEngine from bluesky.utils import DuringTask + from ibex_bluesky_core.callbacks.document_logger import DocLoggingCallback __all__ = ["get_run_engine"] @@ -67,6 +68,6 @@ def get_run_engine() -> RunEngine: RE.record_interruptions = True log_callback = DocLoggingCallback() - RE.subscribe(log_callback) # Uses ID = 0 for DocLoggingCallback + RE.subscribe(log_callback) # Uses ID = 0 for DocLoggingCallback return RE diff --git a/tests/test_run_engine.py b/tests/test_run_engine.py index 5334550..8206599 100644 --- a/tests/test_run_engine.py +++ b/tests/test_run_engine.py @@ -1,6 +1,7 @@ import json -from pathlib import Path +import os import threading +from pathlib import Path from typing import Any, Generator from unittest.mock import MagicMock, mock_open, patch @@ -9,7 +10,6 @@ from bluesky.run_engine import RunEngine, RunEngineResult from bluesky.utils import Msg, RequestAbort, RequestStop, RunEngineInterrupted from ibex_bluesky_core.run_engine import _DuringTask, get_run_engine -import os @pytest.fixture @@ -143,25 +143,29 @@ def test_during_task_does_wait_with_small_timeout(): event.wait.assert_called_with(0.1) assert event.wait.call_count == 2 -def test_run_engine_logs_all_documents(RE): +def test_run_engine_logs_all_documents(RE): m = mock_open() filepath: str - DEFAULT_LOG_LOCATION = Path(os.path.join("C:\\","instrument","var","logs","bluesky","raw_documents")) + log_location = Path( + os.path.join("C:\\", "instrument", "var", "logs", "bluesky", "raw_documents") + ) def basic_plan() -> Generator[Msg, None, None]: yield from bps.open_run() yield from bps.close_run() - with patch('ibex_bluesky_core.callbacks.document_logger.open', m): + with patch("ibex_bluesky_core.callbacks.document_logger.open", m): result: RunEngineResult = RE(basic_plan()) - filepath = os.path.join(DEFAULT_LOG_LOCATION, f"{result.run_start_uids[0]}.log") - - for i in range (0,3): - assert m.call_args_list[i].args == (filepath, 'a') # Checks that the file is opened 3 times, for open, descriptor then stop + filepath = os.path.join(log_location, f"{result.run_start_uids[0]}.log") + + for i in range(0, 3): + assert m.call_args_list[i].args == (filepath, "a") + # Checks that the file is opened 3 times, for open, descriptor then stop handle = m() document = json.loads(handle.write.mock_calls[-1].args[0]) - - assert document['document']['exit_status'] == "success" # In the stop document to be written, check that the run is successful with no interruptions - assert document['document']['num_events']['interruptions'] == 0 + + assert document["document"]["exit_status"] == "success" + # In the stop document to be written, check that the run is successful with no interruptions + assert document["document"]["num_events"]["interruptions"] == 0 From 5132427663b726c2559b578423e672c4bbbda395 Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 11:26:06 +0100 Subject: [PATCH 03/12] Ruff reformating & pyright corrections --- .../callbacks/document_logger.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ibex_bluesky_core/callbacks/document_logger.py b/src/ibex_bluesky_core/callbacks/document_logger.py index 4472f0b..9014b35 100644 --- a/src/ibex_bluesky_core/callbacks/document_logger.py +++ b/src/ibex_bluesky_core/callbacks/document_logger.py @@ -8,33 +8,28 @@ class DocLoggingCallback: - """ - Logs all documents under log_location, with the file name of their UID (.log). - """ + """Logs all documents under log_location, with the file name of their UID (.log).""" def __init__(self) -> None: - """ - Initialises current_start_document and filename. - """ - + """Initialise current_start_document and filename.""" self.current_start_document = None self.filename = None def __call__(self, name: str, document: dict) -> int: - """ - Is called when a new document needs to be processed. Writes document to a file. + """Is called when a new document needs to be processed. Writes document to a file. Args: name: The type of the document e.g start, event, stop document: The contents of the docuement as a dictionary + """ - if name == "start": log_location.mkdir(parents=True, exist_ok=True) self.current_start_document = document["uid"] - self.filename: str = os.path.join(log_location, f"{self.current_start_document}.log") + self.filename = os.path.join(log_location, f"{self.current_start_document}.log") + assert self.filename is not None, "Could not create filename." assert self.current_start_document is not None, "Saw a non-start document before a start." to_write = {"type": name, "document": document} From 0c17ee10fa673f8ab1cc2f9eae69e649af8cbe8a Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 11:27:30 +0100 Subject: [PATCH 04/12] Ruff reformating & pyright corrections --- src/ibex_bluesky_core/callbacks/document_logger.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ibex_bluesky_core/callbacks/document_logger.py b/src/ibex_bluesky_core/callbacks/document_logger.py index 9014b35..5c858bb 100644 --- a/src/ibex_bluesky_core/callbacks/document_logger.py +++ b/src/ibex_bluesky_core/callbacks/document_logger.py @@ -21,7 +21,6 @@ def __call__(self, name: str, document: dict) -> int: Args: name: The type of the document e.g start, event, stop document: The contents of the docuement as a dictionary - """ if name == "start": log_location.mkdir(parents=True, exist_ok=True) From f981ff94061424f1f15fdcb68c70f6df344faeaa Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 11:33:49 +0100 Subject: [PATCH 05/12] Ruff reformating & pyright corrections --- src/ibex_bluesky_core/callbacks/document_logger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ibex_bluesky_core/callbacks/document_logger.py b/src/ibex_bluesky_core/callbacks/document_logger.py index 5c858bb..99350ab 100644 --- a/src/ibex_bluesky_core/callbacks/document_logger.py +++ b/src/ibex_bluesky_core/callbacks/document_logger.py @@ -21,6 +21,7 @@ def __call__(self, name: str, document: dict) -> int: Args: name: The type of the document e.g start, event, stop document: The contents of the docuement as a dictionary + """ if name == "start": log_location.mkdir(parents=True, exist_ok=True) From eeac23df6b9063b233cb891cc2564f5d904b00b5 Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 13:47:16 +0100 Subject: [PATCH 06/12] Various refactorings reg. review comments --- src/ibex_bluesky_core/callbacks/__init__.py | 1 + .../callbacks/document_logger.py | 9 ++--- src/ibex_bluesky_core/run_engine.py | 2 +- tests/conftest.py | 9 +++++ tests/test_document_logging_callback.py | 33 +++++++++++++++ tests/test_run_engine.py | 40 +------------------ 6 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 src/ibex_bluesky_core/callbacks/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/test_document_logging_callback.py diff --git a/src/ibex_bluesky_core/callbacks/__init__.py b/src/ibex_bluesky_core/callbacks/__init__.py new file mode 100644 index 0000000..913b6dc --- /dev/null +++ b/src/ibex_bluesky_core/callbacks/__init__.py @@ -0,0 +1 @@ +"""For callbacks that relate to the BlueSky run engine.""" diff --git a/src/ibex_bluesky_core/callbacks/document_logger.py b/src/ibex_bluesky_core/callbacks/document_logger.py index 99350ab..5651bdb 100644 --- a/src/ibex_bluesky_core/callbacks/document_logger.py +++ b/src/ibex_bluesky_core/callbacks/document_logger.py @@ -1,10 +1,9 @@ """Logs all documents that the BlueSky run engine creates via a callback.""" import json -import os from pathlib import Path -log_location = Path(os.path.join("C:\\", "instrument", "var", "logs", "bluesky", "raw_documents")) +log_location = Path("C:\\") / "instrument" / "var" / "logs" / "bluesky" / "raw_documents" class DocLoggingCallback: @@ -15,7 +14,7 @@ def __init__(self) -> None: self.current_start_document = None self.filename = None - def __call__(self, name: str, document: dict) -> int: + def __call__(self, name: str, document: dict) -> None: """Is called when a new document needs to be processed. Writes document to a file. Args: @@ -27,7 +26,7 @@ def __call__(self, name: str, document: dict) -> int: log_location.mkdir(parents=True, exist_ok=True) self.current_start_document = document["uid"] - self.filename = os.path.join(log_location, f"{self.current_start_document}.log") + self.filename = log_location / f"{self.current_start_document}.log" assert self.filename is not None, "Could not create filename." assert self.current_start_document is not None, "Saw a non-start document before a start." @@ -36,5 +35,3 @@ def __call__(self, name: str, document: dict) -> int: with open(self.filename, "a") as outfile: outfile.write(f"{json.dumps(to_write)}\n") - - return 0 diff --git a/src/ibex_bluesky_core/run_engine.py b/src/ibex_bluesky_core/run_engine.py index 9915cc3..8ddd512 100644 --- a/src/ibex_bluesky_core/run_engine.py +++ b/src/ibex_bluesky_core/run_engine.py @@ -68,6 +68,6 @@ def get_run_engine() -> RunEngine: RE.record_interruptions = True log_callback = DocLoggingCallback() - RE.subscribe(log_callback) # Uses ID = 0 for DocLoggingCallback + RE.subscribe(log_callback) return RE diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..2ecc7b5 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,9 @@ +import pytest +from bluesky.run_engine import RunEngine +from ibex_bluesky_core.run_engine import get_run_engine + + +@pytest.fixture +def RE() -> RunEngine: + get_run_engine.cache_clear() + return get_run_engine() diff --git a/tests/test_document_logging_callback.py b/tests/test_document_logging_callback.py new file mode 100644 index 0000000..ab28653 --- /dev/null +++ b/tests/test_document_logging_callback.py @@ -0,0 +1,33 @@ +import json +from pathlib import Path +from typing import Generator +from unittest.mock import mock_open, patch + +import bluesky.plan_stubs as bps +from bluesky.run_engine import RunEngineResult +from bluesky.utils import Msg + + +def test_run_engine_logs_all_documents(RE): + m = mock_open() + filepath: str + log_location = Path("C:\\") / "instrument" / "var" / "logs" / "bluesky" / "raw_documents" + + def basic_plan() -> Generator[Msg, None, None]: + yield from bps.open_run() + yield from bps.close_run() + + with patch("ibex_bluesky_core.callbacks.document_logger.open", m): + result: RunEngineResult = RE(basic_plan()) + filepath = log_location / f"{result.run_start_uids[0]}.log" + + for i in range(0, 3): + assert m.call_args_list[i].args == (filepath, "a") + # Checks that the file is opened 3 times, for open, descriptor then stop + + handle = m() + document = json.loads(handle.write.mock_calls[-1].args[0]) + + assert document["document"]["exit_status"] == "success" + # In the stop document to be written, check that the run is successful with no interruptions + assert document["document"]["num_events"]["interruptions"] == 0 diff --git a/tests/test_run_engine.py b/tests/test_run_engine.py index 8206599..91dd973 100644 --- a/tests/test_run_engine.py +++ b/tests/test_run_engine.py @@ -1,23 +1,14 @@ -import json -import os import threading -from pathlib import Path from typing import Any, Generator -from unittest.mock import MagicMock, mock_open, patch +from unittest.mock import MagicMock import bluesky.plan_stubs as bps import pytest -from bluesky.run_engine import RunEngine, RunEngineResult +from bluesky.run_engine import RunEngineResult from bluesky.utils import Msg, RequestAbort, RequestStop, RunEngineInterrupted from ibex_bluesky_core.run_engine import _DuringTask, get_run_engine -@pytest.fixture -def RE() -> RunEngine: - get_run_engine.cache_clear() - return get_run_engine() - - def test_run_engine_is_singleton(): re1 = get_run_engine() re2 = get_run_engine() @@ -142,30 +133,3 @@ def test_during_task_does_wait_with_small_timeout(): event.wait.assert_called_with(0.1) assert event.wait.call_count == 2 - - -def test_run_engine_logs_all_documents(RE): - m = mock_open() - filepath: str - log_location = Path( - os.path.join("C:\\", "instrument", "var", "logs", "bluesky", "raw_documents") - ) - - def basic_plan() -> Generator[Msg, None, None]: - yield from bps.open_run() - yield from bps.close_run() - - with patch("ibex_bluesky_core.callbacks.document_logger.open", m): - result: RunEngineResult = RE(basic_plan()) - filepath = os.path.join(log_location, f"{result.run_start_uids[0]}.log") - - for i in range(0, 3): - assert m.call_args_list[i].args == (filepath, "a") - # Checks that the file is opened 3 times, for open, descriptor then stop - - handle = m() - document = json.loads(handle.write.mock_calls[-1].args[0]) - - assert document["document"]["exit_status"] == "success" - # In the stop document to be written, check that the run is successful with no interruptions - assert document["document"]["num_events"]["interruptions"] == 0 From 5f5e106009c428f0fa448135075dc447ca306b3f Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 13:56:36 +0100 Subject: [PATCH 07/12] Pyright && ruff changes --- tests/test_document_logging_callback.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_document_logging_callback.py b/tests/test_document_logging_callback.py index ab28653..cd697d8 100644 --- a/tests/test_document_logging_callback.py +++ b/tests/test_document_logging_callback.py @@ -10,7 +10,6 @@ def test_run_engine_logs_all_documents(RE): m = mock_open() - filepath: str log_location = Path("C:\\") / "instrument" / "var" / "logs" / "bluesky" / "raw_documents" def basic_plan() -> Generator[Msg, None, None]: From 8650c2892eca3b5b8644deaf0c2272a295bc821e Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 14:17:36 +0100 Subject: [PATCH 08/12] Pointed linter to install_proj_dependancies_in_workflow --- .github/workflows/Lint-and-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Lint-and-test.yml b/.github/workflows/Lint-and-test.yml index d6cf780..d4be6c2 100644 --- a/.github/workflows/Lint-and-test.yml +++ b/.github/workflows/Lint-and-test.yml @@ -2,9 +2,9 @@ name: Lint-and-test on: [pull_request, workflow_call] jobs: call-linter-workflow: - uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@main + uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@install_proj_dependancies_in_workflow with: - compare-branch: origin/main + compare-branch: origin/install_proj_dependancies_in_workflow python-ver: '3.11' tests: runs-on: ubuntu-latest From 6b68014665bcc27158a9d7e50948a62bdd6ab3ea Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 14:21:40 +0100 Subject: [PATCH 09/12] Pyright && ruff changes --- .github/workflows/Lint-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Lint-and-test.yml b/.github/workflows/Lint-and-test.yml index d4be6c2..09f7408 100644 --- a/.github/workflows/Lint-and-test.yml +++ b/.github/workflows/Lint-and-test.yml @@ -4,7 +4,7 @@ jobs: call-linter-workflow: uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@install_proj_dependancies_in_workflow with: - compare-branch: origin/install_proj_dependancies_in_workflow + compare-branch: origin/main python-ver: '3.11' tests: runs-on: ubuntu-latest From 1e3466f6609b9681d2fbeea7a3dbc7f8dbad3274 Mon Sep 17 00:00:00 2001 From: Jack Doughty Date: Fri, 9 Aug 2024 14:31:39 +0100 Subject: [PATCH 10/12] Pointed linter to main --- .github/workflows/Lint-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Lint-and-test.yml b/.github/workflows/Lint-and-test.yml index 09f7408..d6cf780 100644 --- a/.github/workflows/Lint-and-test.yml +++ b/.github/workflows/Lint-and-test.yml @@ -2,7 +2,7 @@ name: Lint-and-test on: [pull_request, workflow_call] jobs: call-linter-workflow: - uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@install_proj_dependancies_in_workflow + uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@main with: compare-branch: origin/main python-ver: '3.11' From d895a5896112ca1f3afb3f48ea0d931dcccbaa76 Mon Sep 17 00:00:00 2001 From: Jack Doughty <56323305+jackbdoughty@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:46:56 +0100 Subject: [PATCH 11/12] Create docs_logging_callback.md --- doc/docs_logging_callback.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/docs_logging_callback.md diff --git a/doc/docs_logging_callback.md b/doc/docs_logging_callback.md new file mode 100644 index 0000000..894beb9 --- /dev/null +++ b/doc/docs_logging_callback.md @@ -0,0 +1,5 @@ +# Document Logging Callback + +The document logger is a callback that the BlueSky RunEngine subscribes to unconditionally. After receiving each document it will write documents in the same file with other documents sharing the same start document (In the same run). These logs are stored under `C://instrument/var/logs/bluesky/raw_documents` and are handled by the log rotation. + +Each document is stored in a JSON format so can be both machine and human readable. It is in the format `{"type": name, "document": document}` whereby `name` is the type of the document, e.g start, stop, event, descriptor and the `document` is the document from BlueSky in JSON format. As these files are produced per BlueSky run, these will be useful for debugging. From 93f01b100013e50c8e2e1504717e1a76f913aecd Mon Sep 17 00:00:00 2001 From: Jack Doughty <56323305+jackbdoughty@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:52:24 +0100 Subject: [PATCH 12/12] Update docs_logging_callback.md --- doc/docs_logging_callback.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/docs_logging_callback.md b/doc/docs_logging_callback.md index 894beb9..057702d 100644 --- a/doc/docs_logging_callback.md +++ b/doc/docs_logging_callback.md @@ -1,5 +1,5 @@ # Document Logging Callback -The document logger is a callback that the BlueSky RunEngine subscribes to unconditionally. After receiving each document it will write documents in the same file with other documents sharing the same start document (In the same run). These logs are stored under `C://instrument/var/logs/bluesky/raw_documents` and are handled by the log rotation. +The document logger is a callback that the BlueSky RunEngine subscribes to unconditionally. After receiving each document, if they share the same start document (in the same run) then it will write them to the same file. These logs are stored under `C:/instrument/var/logs/bluesky/raw_documents` and are handled by the log rotation. -Each document is stored in a JSON format so can be both machine and human readable. It is in the format `{"type": name, "document": document}` whereby `name` is the type of the document, e.g start, stop, event, descriptor and the `document` is the document from BlueSky in JSON format. As these files are produced per BlueSky run, these will be useful for debugging. +Each document is stored in a JSON format so can be both machine and human readable. It is in the format `{"type": name, "document": document}` whereby `name` is the type of the document, e.g start, stop, event, descriptor and the `document` is the [document from BlueSky in JSON format](https://blueskyproject.io/bluesky/main/documents.html). As these files are produced per BlueSky run, these will be useful for debugging.