Skip to content

Commit

Permalink
Log mech commands to a separate log file
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 15, 2024
1 parent 36e9ddb commit bc6f621
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 7 additions & 3 deletions yao/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import pathlib
import warnings

from clu import Command
from clu.legacy import LegacyActor

from archon import log as archon_log
from archon.actor.actor import ArchonBaseActor
from archon.actor.tools import get_schema
from clu import Command
from clu.legacy import LegacyActor

from yao import __version__, config
from yao.alerts import AlertsBot
Expand Down Expand Up @@ -57,9 +56,14 @@ def __init__(self, *args, **kwargs):

# TODO: this assumes one single mech controller, not one per spectrograph,
# but in practice for now that's fine.

log_path = self.log.log_filename
mech_log = pathlib.Path(log_path).parent / "spec-mech.log" if log_path else None

self.spec_mech = MechController(
self.config["specMech"]["address"],
self.config["specMech"]["port"],
log_path=str(mech_log),
)

# Add actor log handlers to the archon library to also get that logging.
Expand Down
15 changes: 13 additions & 2 deletions yao/mech_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,28 @@ class MechController:
The port of the host of the mech server.
log
A logger to which to write.
log_path
If ``log=None`` and ``log_path`` is provided, the log is saved to this
location using a rotating file handler.
"""

def __init__(self, address: str, port: int = 23, log: SDSSLogger | None = None):
def __init__(
self,
address: str,
port: int = 23,
log: SDSSLogger | None = None,
log_path: str | None = None,
):
self.reader: asyncio.StreamReader | None = None
self.writer: asyncio.StreamWriter | None = None

self.reboot: bool = False
self.command_number: int = 0

self.log = log or SDSSLogger("boss-spech-mech-client")
self.log = log or SDSSLogger("yao.boss-spech-mech-client")
if log is None and log_path:
self.log.start_file_logger(log_path)

self.spechMechAddress = address
self.specMechPort = port
Expand Down

0 comments on commit bc6f621

Please sign in to comment.