Skip to content

Commit 5ebfb4c

Browse files
Merge pull request #1003 from TheDeanLab/logging-updates
Remove repr, cleanup dependency, combine logs
2 parents eb8bf7b + f335d41 commit 5ebfb4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+111
-150
lines changed

src/navigate/controller/sub_controllers/stages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939

4040
# Local Imports
4141
from navigate.controller.sub_controllers.gui import GUIController
42-
from navigate.model.devices import log_initialization
42+
from navigate.tools.decorators import log_initialization
4343

4444
# Logger Setup
4545
p = __name__.split(".")[1]
4646
logger = logging.getLogger(p)
4747

48+
4849
@log_initialization
4950
class StageController(GUIController):
5051
"""StageController

src/navigate/log_files/filters.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,3 @@ def filter(self, record):
9797
if record.getMessage().startswith("Spec"):
9898
return False
9999
return True
100-
101-
class DebugFilter(logging.Filter):
102-
"""
103-
A custom logging filter to include only DEBUG level messages.
104-
"""
105-
def filter(self, record):
106-
return record.levelno == logging.DEBUG

src/navigate/log_files/logging.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ filters:
99
(): ext://navigate.log_files.filters.PerformanceFilter
1010
not_performance:
1111
(): ext://navigate.log_files.filters.NonPerfFilter
12-
only_debug:
13-
(): ext://navigate.log_files.filters.DebugFilter
1412
handlers:
1513
console:
1614
class: logging.StreamHandler
@@ -30,29 +28,19 @@ handlers:
3028
level: DEBUG
3129
formatter: base
3230
filename: view_controller_debug.log
33-
filters: [not_performance, only_debug]
31+
filters: [not_performance]
3432
mode: a
35-
# performance:
36-
# class: logging.handlers.RotatingFileHandler
37-
# level: DEBUG
38-
# formatter: base
39-
# filename: view_controller_performance.log
40-
# filters: [performance_specs]
41-
# mode: a
4233
loggers:
4334
view:
4435
level: DEBUG
45-
# handlers: [console, vc_info, vc_debug, performance]
4636
handlers: [console, vc_info, vc_debug]
4737
propagate: no
4838
controller:
4939
level: DEBUG
50-
# handlers: [console, vc_info, vc_debug, performance]
5140
handlers: [console, vc_info, vc_debug]
5241
propagate: no
5342
config:
5443
level: DEBUG
55-
# handlers: [console, vc_info, vc_debug, performance]
5644
handlers: [console, vc_info, vc_debug]
5745
propagate: no
5846

src/navigate/log_files/model_logging.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ filters:
99
(): ext://navigate.log_files.filters.PerformanceFilter
1010
not_performance:
1111
(): ext://navigate.log_files.filters.NonPerfFilter
12-
only_debug:
13-
(): ext://navigate.log_files.filters.DebugFilter
1412
handlers:
1513
console:
1614
class: logging.StreamHandler
@@ -30,7 +28,7 @@ handlers:
3028
level: DEBUG
3129
formatter: base
3230
filename: model_debug.log
33-
filters: [not_performance, only_debug]
31+
filters: [not_performance]
3432
mode: a
3533
model_error:
3634
class: logging.handlers.RotatingFileHandler
@@ -39,13 +37,6 @@ handlers:
3937
filename: model_error.log
4038
filters: [not_performance]
4139
mode: a
42-
# model_performance:
43-
# class: logging.handlers.RotatingFileHandler
44-
# level: DEBUG
45-
# formatter: base
46-
# filename: model_performance.log
47-
# filters: [performance_specs]
48-
# mode: a
4940
loggers:
5041
model:
5142
level: DEBUG
Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,17 @@
11
""" Hardware devices. """
22

33
# Standard library imports
4-
from functools import wraps
5-
import logging
6-
import reprlib
74

85
# Third party imports
96

107
# Local imports
11-
# from .daq.synthetic import SyntheticDAQ # noqa
12-
# from .camera.synthetic import SyntheticCamera # noqa
13-
# from .filter_wheel.synthetic import SyntheticFilterWheel # noqa
14-
# from .galvo.synthetic import SyntheticGalvo # noqa
15-
# from .remote_focus.synthetic import SyntheticRemoteFocus # noqa
16-
# from .shutter.synthetic import SyntheticShutter # noqa
17-
# from .stages.synthetic import SyntheticStage # noqa
18-
# from .zoom.synthetic import SyntheticZoom # noqa
19-
# from .lasers.synthetic import SyntheticLaser # noqa
20-
# from .mirrors.synthetic import SyntheticMirror # noqa
21-
22-
def log_initialization(cls):
23-
"""Decorator for logging the initialization of a device class.
24-
25-
Parameters
26-
----------
27-
cls : class
28-
The class to be logged.
29-
30-
Returns
31-
-------
32-
cls : class
33-
The class with the logging decorator.
34-
"""
35-
# Set up the reprlib object
36-
mod_repr = reprlib.Repr()
37-
mod_repr.indent = 4
38-
mod_repr.maxstring = 50
39-
mod_repr.maxother = 50
40-
41-
# Get the original __init__ method
42-
original_init = cls.__init__
43-
44-
@wraps(original_init)
45-
def new_init(self, *args, **kwargs):
46-
module_location = cls.__module__
47-
logger = logging.getLogger(module_location.split(".")[1])
48-
try:
49-
original_init(self, *args, **kwargs)
50-
logger.info(f"{mod_repr.repr(cls.__name__)}, "
51-
f"{mod_repr.repr(args)}, "
52-
f"{mod_repr.repr(kwargs)}"
53-
)
54-
except Exception as e:
55-
logger.error(f"{mod_repr.repr(cls.__name__)} Initialization Failed")
56-
logger.error(f"Input args & kwargs: {args}, {kwargs}")
57-
logger.error(f"Error: {e}")
58-
raise e
59-
60-
# Replace the original __init__ method with the new one
61-
cls.__init__ = new_init
62-
return cls
8+
from .daq.synthetic import SyntheticDAQ # noqa
9+
from .camera.synthetic import SyntheticCamera # noqa
10+
from .filter_wheel.synthetic import SyntheticFilterWheel # noqa
11+
from .galvo.synthetic import SyntheticGalvo # noqa
12+
from .remote_focus.synthetic import SyntheticRemoteFocus # noqa
13+
from .shutter.synthetic import SyntheticShutter # noqa
14+
from .stages.synthetic import SyntheticStage # noqa
15+
from .zoom.synthetic import SyntheticZoom # noqa
16+
from .lasers.synthetic import SyntheticLaser # noqa
17+
from .mirrors.synthetic import SyntheticMirror # noqa

src/navigate/model/devices/camera/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939

4040
# Local Imports
4141
from navigate.config import get_navigate_path
42-
from navigate.model.devices import log_initialization
42+
from navigate.tools.decorators import log_initialization
4343

4444
# Logger Setup
4545
p = __name__.split(".")[1]
4646
logger = logging.getLogger(p)
4747

48+
4849
@log_initialization
4950
class CameraBase:
5051
"""CameraBase - Parent camera class."""
@@ -163,8 +164,9 @@ def get_offset_variance_maps(self):
163164
os.path.join(map_path, f"{serial_number}_var.tiff")
164165
)
165166
except FileNotFoundError:
166-
logger.info(f"{str(self)}, Offset or variance map not found in"
167-
f" {map_path}")
167+
logger.info(
168+
f"{str(self)}, Offset or variance map not found in {map_path}"
169+
)
168170
self._offset, self._variance = None, None
169171
return self._offset, self._variance
170172

src/navigate/model/devices/camera/hamamatsu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
# Local Imports
3939
from navigate.model.devices.camera.base import CameraBase
40-
from navigate.model.devices import log_initialization
40+
from navigate.tools.decorators import log_initialization
41+
4142
# Logger Setup
4243
p = __name__.split(".")[1]
4344
logger = logging.getLogger(p)

src/navigate/model/devices/camera/photometrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
# Local Imports
4343
from navigate.model.devices.camera.base import CameraBase
44-
from navigate.model.devices import log_initialization
44+
from navigate.tools.decorators import log_initialization
4545

4646
# Logger Setup
4747
p = __name__.split(".")[1]

src/navigate/model/devices/camera/synthetic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# Local Imports
4343
from navigate.model.analysis import camera
4444
from navigate.model.devices.camera.base import CameraBase
45-
from navigate.model.devices import log_initialization
45+
from navigate.tools.decorators import log_initialization
4646

4747
# Logger Setup
4848
p = __name__.split(".")[1]

src/navigate/model/devices/daq/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737

3838
# Local Imports
3939
from navigate.model.waveforms import camera_exposure
40-
from navigate.model.devices import log_initialization
40+
from navigate.tools.decorators import log_initialization
4141

4242
# Logger Setup
4343
p = __name__.split(".")[1]
4444
logger = logging.getLogger(p)
4545

46+
4647
@log_initialization
4748
class DAQBase:
4849
"""DAQBase - Parent class for Data Acquisition (DAQ) classes."""

0 commit comments

Comments
 (0)