Skip to content

Replace print statements with logging statements #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mavsdk/async_plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import logging
import aiogrpc


Expand Down Expand Up @@ -29,9 +30,12 @@ async def _connect_backend(self):
"{}:{}".format(self.host, self.port)
)

print("Waiting for mavsdk_server to be ready...")
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler()) # Avoid errors when user has not configured logging

logger.debug("Waiting for mavsdk_server to be ready...")
await aiogrpc.channel_ready_future(self._channel)
print("Connected to mavsdk_server!")
logger.debug("Connected to mavsdk_server!")

@property
def channel(self):
Expand Down
21 changes: 19 additions & 2 deletions mavsdk/system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-

import logging
import threading

from .async_plugin_manager import AsyncPluginManager

from . import action
Expand Down Expand Up @@ -28,6 +31,16 @@
from . import bin


class _LoggingThread(threading.Thread):
def __init__(self, pipe, log_fn):
super().__init__()
self.pipe = pipe
self.log_fn = log_fn

def run(self):
for line in self.pipe:
self.log_fn(line.decode("utf-8").replace("\n", ""))

class System:
"""
Instantiate a System object, that will serve as a proxy to
Expand Down Expand Up @@ -281,8 +294,12 @@ def _start_mavsdk_server(system_address=None,port=50051):
bin_path_and_args.append(system_address)
p = subprocess.Popen(bin_path_and_args,
shell=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)

logger = logging.getLogger(__name__)
log_thread = _LoggingThread(p.stdout, logger.debug)
log_thread.start()
except FileNotFoundError:
print("""
This installation does not provide an embedded 'mavsdk_server' binary.
Expand Down