fix(logger): to support logger for multiple runs through port assignment#71
fix(logger): to support logger for multiple runs through port assignment#71BinWang28 merged 3 commits intomiroflow-v0.3from
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the logger to support multiple concurrent runs by implementing dynamic port assignment for ZMQ connections. Instead of using a fixed port that could cause conflicts, the system now automatically finds available ports and manages the ZMQ address globally.
- Adds dynamic port discovery to prevent port conflicts between multiple logger instances
- Implements global ZMQ address management with getter/setter functions
- Adds graceful fallback handling when ZMQ connections fail
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/logging/logger.py
Outdated
| return actual_addr | ||
| except RuntimeError: | ||
| # Fallback to random port | ||
| return sock.bind_to_random_port("tcp://127.0.0.1") |
There was a problem hiding this comment.
The bind_to_random_port method returns a port number, not an address string. This should be port = sock.bind_to_random_port('tcp://127.0.0.1') followed by return f'tcp://127.0.0.1:{port}' to maintain consistent return type.
| return sock.bind_to_random_port("tcp://127.0.0.1") | |
| port = sock.bind_to_random_port("tcp://127.0.0.1") | |
| return f"tcp://127.0.0.1:{port}" |
src/logging/logger.py
Outdated
| print(f"ZMQ handler connected to: {addr}") | ||
| except zmq.error.ZMQError as e: | ||
| # If connection fails, disable the handler | ||
| print(f"Warning: Could not connect to ZMQ listener at {addr}: {e}") | ||
| print("Disabling ZMQ logging for this handler") |
There was a problem hiding this comment.
Direct print() statements should be replaced with proper logging calls. Use logger.info() for connection messages and logger.warning() for connection failures to maintain consistent logging practices.
| print(f"ZMQ handler connected to: {addr}") | |
| except zmq.error.ZMQError as e: | |
| # If connection fails, disable the handler | |
| print(f"Warning: Could not connect to ZMQ listener at {addr}: {e}") | |
| print("Disabling ZMQ logging for this handler") | |
| logging.info(f"ZMQ handler connected to: {addr}") | |
| except zmq.error.ZMQError as e: | |
| # If connection fails, disable the handler | |
| logging.warning(f"Could not connect to ZMQ listener at {addr}: {e}") | |
| logging.warning("Disabling ZMQ logging for this handler") |
src/logging/logger.py
Outdated
| # Bind to available port | ||
| actual_addr = _bind_zmq_socket(sock, bind_addr) | ||
| set_zmq_address(actual_addr) | ||
| print(f"ZMQ listener bound to: {actual_addr}") |
There was a problem hiding this comment.
Direct print() statements should be replaced with proper logging calls. Use logger.info() for connection messages and logger.warning() for connection failures to maintain consistent logging practices.
| print(f"ZMQ listener bound to: {actual_addr}") | |
| root_logger.info(f"ZMQ listener bound to: {actual_addr}") |
src/logging/logger.py
Outdated
| if self.sock is not None: | ||
| msg = f"{record.getMessage()}" | ||
| self.sock.send_string(f"{self.task_id}||{self.tool_name}||{msg}") |
There was a problem hiding this comment.
The emit method should return early when self.sock is None instead of nesting all the logging logic inside an if statement. This would improve readability and reduce indentation depth.
| if self.sock is not None: | |
| msg = f"{record.getMessage()}" | |
| self.sock.send_string(f"{self.task_id}||{self.tool_name}||{msg}") | |
| if self.sock is None: | |
| return | |
| msg = f"{record.getMessage()}" | |
| self.sock.send_string(f"{self.task_id}||{self.tool_name}||{msg}") |
…ent (MiroMindAI#71) * to pass lint * accomodate copilot suggests * pass lint
as titled
Checklist for PR
Write a descriptive PR title following the Angular commit message format:
<type>(<scope>): <subject>feat(agent): add pdf tool via mcp,perf: make llm client async,fix(utils): load custom config via importlibfeat,fix,docs,style,refactor,perf,test,build,ci,revertcheck-pr-titleCI job will validate your title formatUpdate README❌ Missing type and colonfeat add new feature❌ Missing colon after typeFeature: add new tool❌ Invalid type (should befeat)feat(Agent): add tool❌ Scope should be lowercasefeat(): add tool❌ Empty scope not allowedfeat(my_scope): add tool❌ Underscores not allowed in scopefeat(my space): add tool❌ Space not allowed in scopefeat(scope):add tool❌ Missing space after colonfeat(scope):❌ Empty subjectRun lint and format locally:
uv tool run ruff@0.8.0 check --fix .uv tool run ruff@0.8.0 format .lintenforces ruff default format/lint rules on all new codes.