diff --git a/docs/source/apis.rst b/docs/source/apis.rst index cd4ce714..f9290472 100644 --- a/docs/source/apis.rst +++ b/docs/source/apis.rst @@ -165,17 +165,3 @@ Convenience classes for special Java objects .. autoclass:: Studio :members: - - -Logging control -############### - -set_logging_instance -==================== - -.. autofunction:: set_logging_instance - -reset_logger_instance -===================== - -.. autofunction:: reset_logger_instance diff --git a/pycromanager/__init__.py b/pycromanager/__init__.py index 3026a3bc..c2e7d09c 100644 --- a/pycromanager/__init__.py +++ b/pycromanager/__init__.py @@ -8,6 +8,5 @@ from pycromanager.core import Core from pyjavaz import JavaObject, JavaClass, PullSocket, PushSocket from pycromanager.acquisition.acq_eng_py.main.acq_notification import AcqNotification -from pycromanager.logging import set_logger_instance, reset_logger_instance from ndtiff import Dataset from ._version import __version__, version_info diff --git a/pycromanager/_version.py b/pycromanager/_version.py index 0dc10aa3..a5ba57d7 100644 --- a/pycromanager/_version.py +++ b/pycromanager/_version.py @@ -1,2 +1,2 @@ -version_info = (0, 32, 1) +version_info = (0, 33, 0) __version__ = ".".join(map(str, version_info)) diff --git a/pycromanager/acquisition/java_backend_acquisitions.py b/pycromanager/acquisition/java_backend_acquisitions.py index 83a6d294..441fbb94 100644 --- a/pycromanager/acquisition/java_backend_acquisitions.py +++ b/pycromanager/acquisition/java_backend_acquisitions.py @@ -2,6 +2,7 @@ The Pycro-manager Acquisiton system """ import json +import logging import warnings import weakref @@ -15,7 +16,7 @@ from pyjavaz import DEFAULT_BRIDGE_PORT as DEFAULT_PORT from pycromanager.mm_java_classes import ZMQRemoteMMCoreJ, Magellan from pycromanager.acquisition.java_RAMStorage import JavaRAMDataStorage -import pycromanager.logging as logging + from ndtiff import Dataset import os.path import queue @@ -25,6 +26,8 @@ from pycromanager.acq_future import AcqNotification, AcquisitionFuture import json +logger = logging.getLogger(__name__) + ### These functions are defined outside the Acquisition class to # prevent problems with pickling when running them in differnet process @@ -36,7 +39,7 @@ def _run_acq_event_source(acquisition, event_port, event_queue, debug=False): while True: events = event_queue.get(block=True) if debug: - logging.main_logger.debug(f"got event(s): {events}") + logger.debug(f"got event(s): {events}") if events is None: # Initiate the normal shutdown process if not acquisition._acq.is_finished(): @@ -54,7 +57,7 @@ def _run_acq_event_source(acquisition, event_port, event_queue, debug=False): # maybe consider putting a timeout on the send? event_socket.send({"events": events if type(events) == list else [events]}) if debug: - logging.main_logger.debug("sent events") + logger.debug("sent events") except Exception as e: acquisition.abort(e) finally: @@ -109,7 +112,7 @@ def _run_image_processor( push_socket = PushSocket(pull_port, debug=debug) pull_socket = PullSocket(push_port, debug=debug) if debug: - logging.main_logger.debug("image processing sockets connected") + logger.debug("image processing sockets connected") sockets_connected_evt.set() def process_and_sendoff(image_tags_tuple, original_dtype): diff --git a/pycromanager/headless.py b/pycromanager/headless.py index 6ba4dfbf..7fb290ef 100644 --- a/pycromanager/headless.py +++ b/pycromanager/headless.py @@ -1,3 +1,4 @@ +import logging import subprocess import platform import atexit @@ -7,12 +8,13 @@ from pycromanager.acquisition.acq_eng_py.internal.engine import Engine from pymmcore import CMMCore -import pycromanager.logging as logging import pymmcore from pyjavaz import DEFAULT_BRIDGE_PORT, server_terminated import re +logger = logging.getLogger(__name__) + class TaggedImage: def __init__(self, tags, pix): @@ -94,29 +96,29 @@ def stop_headless(debug=False): for p in _JAVA_HEADLESS_SUBPROCESSES: port = p.port if debug: - logging.main_logger.debug('Stopping headless process with pid {}'.format(p.pid)) + logger.debug('Stopping headless process with pid {}'.format(p.pid)) p.terminate() server_terminated(port) if debug: - logging.main_logger.debug('Waiting for process with pid {} to terminate'.format(p.pid)) + logger.debug('Waiting for process with pid {} to terminate'.format(p.pid)) p.wait() # wait for process to terminate if debug: - logging.main_logger.debug('Process with pid {} terminated'.format(p.pid)) + logger.debug('Process with pid {} terminated'.format(p.pid)) _JAVA_HEADLESS_SUBPROCESSES.clear() if debug: - logging.main_logger.debug('Stopping {} pymmcore instances'.format(len(_PYMMCORES))) + logger.debug('Stopping {} pymmcore instances'.format(len(_PYMMCORES))) for c in _PYMMCORES: if debug: - logging.main_logger.debug('Stopping pymmcore instance') + logger.debug('Stopping pymmcore instance') c.unloadAllDevices() if debug: - logging.main_logger.debug('Unloaded all devices') + logger.debug('Unloaded all devices') Engine.get_instance().shutdown() if debug: - logging.main_logger.debug('Engine shut down') + logger.debug('Engine shut down') _PYMMCORES.clear() if debug: - logging.main_logger.debug('Headless stopped') + logger.debug('Headless stopped') # make sure any Java processes are cleaned up when Python exits atexit.register(stop_headless) @@ -177,13 +179,13 @@ def start_headless( else: java_loc = "java" if debug: - logging.main_logger.debug(f'Java location: {java_loc}') + logger.debug(f'Java location: {java_loc}') #print classpath - logging.main_logger.debug(f'Classpath: {classpath}') + logger.debug(f'Classpath: {classpath}') # print stuff in the classpath directory - logging.main_logger.debug('Contents of classpath directory:') + logger.debug('Contents of classpath directory:') for f in os.listdir(classpath.split('*')[0]): - logging.main_logger.debug(f) + logger.debug(f) # This starts Java process and instantiates essential objects (core, # acquisition engine, ZMQServer) @@ -215,12 +217,12 @@ def start_headless( if not started: raise Exception('Error starting headless mode') if debug: - logging.main_logger.debug('Headless mode started') + logger.debug('Headless mode started') def loggerFunction(): while process in _JAVA_HEADLESS_SUBPROCESSES: line = process.stdout.readline().decode('utf-8') if line.strip() != '': - logging.main_logger.debug(line) + logger.debug(line) threading.Thread(target=loggerFunction).start() diff --git a/pycromanager/logging.py b/pycromanager/logging.py deleted file mode 100644 index 9304e018..00000000 --- a/pycromanager/logging.py +++ /dev/null @@ -1,16 +0,0 @@ -import logging - -main_logger = _base_logger = logging.getLogger("pycromanager") - -def set_logger_instance(logger_name: str) -> None: - """ Replaces the default logger with a custom logger - - logger (str) - name of new logger to use (i.e. logger.name) - """ - global main_logger - main_logger = logging.getLogger(logger_name) - -def reset_logger_instance() -> None: - """ Resets the logger to the default logger """ - set_logger_instance(_base_logger.name) diff --git a/requirements.txt b/requirements.txt index a56573ba..c47a8683 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,4 @@ ndtiff>=2.3.0 docstring-inheritance pymmcore sortedcontainers -pyjavaz==1.1.0 +pyjavaz==1.1.1