Skip to content

Commit

Permalink
Merge pull request #113 from IBM/even_better_startup_logging
Browse files Browse the repository at this point in the history
Move all log setup to before first message (for real)
  • Loading branch information
gabe-l-hart authored Aug 29, 2024
2 parents fb06355 + d8ee532 commit 01e2305
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,27 +262,17 @@ def __init__(

def start(
self,
logging_queue: multiprocessing.Queue,
request: ReconcileRequest,
result_pipe: Connection,
):
"""Main entrypoint for the class
Args:
logging_queue: multiprocessing.Queue
The queue to pass log messages to
request: ReconcileRequest
The reconcile request that trigger this reconciliation
result_pipe: Connection
The connection to send results back to
"""
# Set the logging library to utilize the multiprocessing logging queue. Do this before
# any logging messages are sent
root_logger = logging.getLogger()
root_logger.handlers.clear()
handler = LogQueueHandler(logging_queue, request.resource)
root_logger.addHandler(handler)

# Parse the request and setup local variables
log.debug4("Setting up resource")
resource = request.resource
Expand Down Expand Up @@ -350,7 +340,6 @@ def start(
log.debug3("Sending reconciliation result back to main process")
result_pipe.send(reconcile_result)
result_pipe.close()
logging_queue.close()


def create_and_start_entrypoint(
Expand All @@ -371,11 +360,21 @@ def create_and_start_entrypoint(
An optional DeployManager override
"""
try:
# Set the logging library to utilize the multiprocessing logging queue. Do this before
# any logging messages are sent since that might cause a deadlock
root_logger = logging.getLogger()
root_logger.handlers.clear()
handler = LogQueueHandler(logging_queue, request.resource)
root_logger.addHandler(handler)

log.debug3("Creating entrypoint")
entry = ReconcileProcessEntrypoint(
request.controller_type, deploy_manager=deploy_manager
)
log.debug3("Starting entrypoint")
entry.start(logging_queue, request, result_pipe)
entry.start(request, result_pipe)
except Exception as exc: # pylint: disable=broad-exception-caught
log.error("Uncaught exception '%s'", exc, exc_info=True)

# Close the logging queue to ensure all messages are sent before process end
logging_queue.close()

0 comments on commit 01e2305

Please sign in to comment.