diff --git a/.vscode/settings.json b/.vscode/settings.json index e0ff04e1..c6696abb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -102,5 +102,7 @@ "." ], "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true + "python.testing.pytestEnabled": true, + "python-envs.defaultEnvManager": "ms-python.python:system", + "python-envs.pythonProjects": [] } diff --git a/apps/auracast.py b/apps/auracast.py index 2fd930d1..5dbcbb74 100644 --- a/apps/auracast.py +++ b/apps/auracast.py @@ -23,7 +23,6 @@ import contextlib import dataclasses import functools import logging -import os import struct from typing import ( Any, @@ -54,6 +53,8 @@ from bumble.profiles import bass import bumble.device import bumble.transport import bumble.utils +import bumble.logging + # ----------------------------------------------------------------------------- # Logging @@ -1235,7 +1236,7 @@ def transmit( def main(): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() auracast() diff --git a/apps/bench.py b/apps/bench.py index e0df3369..d7e9fcd7 100644 --- a/apps/bench.py +++ b/apps/bench.py @@ -19,7 +19,6 @@ import asyncio import dataclasses import enum import logging -import os import statistics import struct import time @@ -70,6 +69,7 @@ import bumble.rfcomm import bumble.core from bumble.utils import AsyncRunner from bumble.pairing import PairingConfig +import bumble.logging # ----------------------------------------------------------------------------- @@ -2321,11 +2321,7 @@ def peripheral(ctx, transport): def main(): - logging.basicConfig( - level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper(), - format="[%(asctime)s.%(msecs)03d] %(levelname)s:%(name)s:%(message)s", - datefmt="%H:%M:%S", - ) + bumble.logging.setup_basic_logging('INFO') bench() diff --git a/apps/controller_info.py b/apps/controller_info.py index efda7143..f71b1782 100644 --- a/apps/controller_info.py +++ b/apps/controller_info.py @@ -16,8 +16,6 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os -import logging import time import click @@ -59,6 +57,7 @@ from bumble.hci import ( ) from bumble.host import Host from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -342,11 +341,7 @@ async def async_main( ) @click.argument('transport') def main(latency_probes, latency_probe_interval, latency_probe_command, transport): - logging.basicConfig( - level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper(), - format="[%(asctime)s.%(msecs)03d] %(levelname)s:%(name)s:%(message)s", - datefmt="%H:%M:%S", - ) + bumble.logging.setup_basic_logging() asyncio.run( async_main( latency_probes, latency_probe_interval, latency_probe_command, transport diff --git a/apps/controller_loopback.py b/apps/controller_loopback.py index a2bdffed..22a7502e 100644 --- a/apps/controller_loopback.py +++ b/apps/controller_loopback.py @@ -16,10 +16,11 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging -import os import time from typing import Optional + +import click + from bumble.colors import color from bumble.hci import ( HCI_READ_LOOPBACK_MODE_COMMAND, @@ -30,7 +31,7 @@ from bumble.hci import ( ) from bumble.host import Host from bumble.transport import open_transport -import click +import bumble.logging class Loopback: @@ -194,12 +195,7 @@ class Loopback: ) @click.argument('transport') def main(packet_size, packet_count, transport): - logging.basicConfig( - level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper(), - format="[%(asctime)s.%(msecs)03d] %(levelname)s:%(name)s:%(message)s", - datefmt="%H:%M:%S", - ) - + bumble.logging.setup_basic_logging() loopback = Loopback(packet_size, packet_count, transport) asyncio.run(loopback.run()) diff --git a/apps/controllers.py b/apps/controllers.py index 09974a86..4584aab2 100644 --- a/apps/controllers.py +++ b/apps/controllers.py @@ -15,14 +15,13 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -import logging import asyncio import sys -import os from bumble.controller import Controller from bumble.link import LocalLink from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -62,7 +61,7 @@ async def async_main(): # ----------------------------------------------------------------------------- def main(): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() asyncio.run(async_main()) diff --git a/apps/device_info.py b/apps/device_info.py index 979546d8..fb860ec9 100644 --- a/apps/device_info.py +++ b/apps/device_info.py @@ -16,8 +16,6 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os -import logging from typing import Callable, Iterable, Optional import click @@ -33,6 +31,7 @@ from bumble.profiles.pacs import PublishedAudioCapabilitiesServiceProxy from bumble.profiles.tmap import TelephonyAndMediaAudioServiceProxy from bumble.profiles.vcs import VolumeControlServiceProxy from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -267,7 +266,7 @@ def main(device_config, encrypt, transport, address_or_name): Dump the GATT database on a remote device. If ADDRESS_OR_NAME is not specified, wait for an incoming connection. """ - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() asyncio.run(async_main(device_config, encrypt, transport, address_or_name)) diff --git a/apps/gatt_dump.py b/apps/gatt_dump.py index c09dc8ae..5633edff 100644 --- a/apps/gatt_dump.py +++ b/apps/gatt_dump.py @@ -16,8 +16,7 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os -import logging + import click import bumble.core @@ -25,6 +24,7 @@ from bumble.colors import color from bumble.device import Device, Peer from bumble.gatt import show_services from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -112,7 +112,7 @@ def main(device_config, encrypt, transport, address_or_name): Dump the GATT database on a remote device. If ADDRESS_OR_NAME is not specified, wait for an incoming connection. """ - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() asyncio.run(async_main(device_config, encrypt, transport, address_or_name)) diff --git a/apps/gg_bridge.py b/apps/gg_bridge.py index 9fb27de3..f8526b28 100644 --- a/apps/gg_bridge.py +++ b/apps/gg_bridge.py @@ -16,9 +16,8 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os import struct -import logging + import click from bumble import l2cap @@ -29,6 +28,7 @@ from bumble.gatt import Service, Characteristic, CharacteristicValue from bumble.utils import AsyncRunner from bumble.transport import open_transport from bumble.hci import HCI_Constant +import bumble.logging # ----------------------------------------------------------------------------- @@ -383,6 +383,7 @@ def main( receive_host, receive_port, ): + bumble.logging.setup_basic_logging('WARNING') asyncio.run( run( hci_transport, @@ -397,6 +398,5 @@ def main( # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper()) if __name__ == '__main__': main() diff --git a/apps/hci_bridge.py b/apps/hci_bridge.py index 883166c3..18f069e7 100644 --- a/apps/hci_bridge.py +++ b/apps/hci_bridge.py @@ -17,11 +17,12 @@ # ----------------------------------------------------------------------------- import logging import asyncio -import os import sys from bumble import hci, transport from bumble.bridge import HCI_Bridge +import bumble.logging + # ----------------------------------------------------------------------------- # Logging @@ -100,7 +101,7 @@ async def async_main(): # ----------------------------------------------------------------------------- def main(): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() asyncio.run(async_main()) diff --git a/apps/l2cap_bridge.py b/apps/l2cap_bridge.py index 89d3a14c..7ca31468 100644 --- a/apps/l2cap_bridge.py +++ b/apps/l2cap_bridge.py @@ -16,8 +16,7 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging -import os + import click from bumble import l2cap @@ -26,6 +25,7 @@ from bumble.transport import open_transport from bumble.device import Device from bumble.utils import FlowControlAsyncPipe from bumble.hci import HCI_Constant +import bumble.logging # ----------------------------------------------------------------------------- @@ -356,6 +356,6 @@ def client(context, bluetooth_address, tcp_host, tcp_port): # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper()) if __name__ == '__main__': + bumble.logging.setup_basic_logging('WARNING') cli(obj={}) # pylint: disable=no-value-for-parameter diff --git a/apps/lea_unicast/app.py b/apps/lea_unicast/app.py index 79975def..0ffb9da5 100644 --- a/apps/lea_unicast/app.py +++ b/apps/lea_unicast/app.py @@ -22,7 +22,6 @@ import datetime import functools from importlib import resources import json -import os import logging import pathlib import weakref @@ -44,6 +43,7 @@ from bumble.device import Device, DeviceConfiguration, AdvertisingParameters, Ci from bumble.transport import open_transport from bumble.profiles import ascs, bap, pacs from bumble.hci import Address, CodecID, CodingFormat, HCI_IsoDataPacket +import bumble.logging # ----------------------------------------------------------------------------- @@ -454,7 +454,7 @@ def speaker(ui_port: int, device_config: str, transport: str, lc3_file: str) -> # ----------------------------------------------------------------------------- def main(): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() speaker() diff --git a/apps/player/player.py b/apps/player/player.py index 448b8cc2..f1454c1f 100644 --- a/apps/player/player.py +++ b/apps/player/player.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- from __future__ import annotations import asyncio -import asyncio.subprocess -import os import logging from typing import Optional, Union @@ -63,6 +61,7 @@ from bumble.hci import Address, HCI_CONNECTION_ALREADY_EXISTS_ERROR, HCI_Constan from bumble.pairing import PairingConfig from bumble.transport import open_transport from bumble.utils import AsyncRunner +import bumble.logging # ----------------------------------------------------------------------------- @@ -599,7 +598,7 @@ def play(context, address, audio_format, audio_file): # ----------------------------------------------------------------------------- def main(): - logging.basicConfig(level=os.environ.get("BUMBLE_LOGLEVEL", "WARNING").upper()) + bumble.logging.setup_basic_logging("WARNING") player_cli() diff --git a/apps/rfcomm_bridge.py b/apps/rfcomm_bridge.py index 5946b102..90a08244 100644 --- a/apps/rfcomm_bridge.py +++ b/apps/rfcomm_bridge.py @@ -16,8 +16,6 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging -import os import time from typing import Optional @@ -30,6 +28,7 @@ from bumble import hci from bumble import rfcomm from bumble import transport from bumble import utils +import bumble.logging # ----------------------------------------------------------------------------- @@ -515,6 +514,6 @@ def client(context, bluetooth_address, tcp_host, tcp_port, authenticate, encrypt # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get("BUMBLE_LOGLEVEL", "WARNING").upper()) if __name__ == "__main__": + bumble.logging.setup_basic_logging("WARNING") cli(obj={}) # pylint: disable=no-value-for-parameter diff --git a/apps/scan.py b/apps/scan.py index 9de272dc..7d1fc9b2 100644 --- a/apps/scan.py +++ b/apps/scan.py @@ -16,8 +16,6 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os -import logging import click from bumble.colors import color @@ -27,6 +25,7 @@ from bumble.keys import JsonKeyStore from bumble.smp import AddressResolver from bumble.device import Advertisement from bumble.hci import Address, HCI_Constant, HCI_LE_1M_PHY, HCI_LE_CODED_PHY +import bumble.logging # ----------------------------------------------------------------------------- @@ -237,7 +236,7 @@ def main( device_config, transport, ): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper()) + bumble.logging.setup_basic_logging('WARNING') asyncio.run( scan( min_rssi, diff --git a/apps/show.py b/apps/show.py index 64cd0a08..1a443dc3 100644 --- a/apps/show.py +++ b/apps/show.py @@ -18,7 +18,6 @@ import datetime import importlib import logging -import os import struct import click @@ -27,6 +26,7 @@ from bumble.colors import color from bumble import hci from bumble.transport.common import PacketReader from bumble.helpers import PacketTracer +import bumble.logging # ----------------------------------------------------------------------------- @@ -188,5 +188,5 @@ def main(format, vendor, filename): # ----------------------------------------------------------------------------- if __name__ == '__main__': - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper()) + bumble.logging.setup_basic_logging('WARNING') main() # pylint: disable=no-value-for-parameter diff --git a/apps/speaker/speaker.py b/apps/speaker/speaker.py index e083c887..b4f206b9 100644 --- a/apps/speaker/speaker.py +++ b/apps/speaker/speaker.py @@ -21,7 +21,6 @@ import asyncio.subprocess from importlib import resources import enum import json -import os import logging import pathlib import subprocess @@ -58,6 +57,7 @@ from bumble.a2dp import ( from bumble.utils import AsyncRunner from bumble.codecs import AacAudioRtpPacket from bumble.rtp import MediaPacket +import bumble.logging # ----------------------------------------------------------------------------- @@ -833,11 +833,7 @@ def speaker( # ----------------------------------------------------------------------------- def main(): - logging.basicConfig( - level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper(), - format="[%(asctime)s.%(msecs)03d] %(levelname)s:%(name)s:%(message)s", - datefmt="%H:%M:%S", - ) + bumble.logging.setup_basic_logging('WARNING') speaker() diff --git a/apps/unbond.py b/apps/unbond.py index 01cb9e50..acef475f 100644 --- a/apps/unbond.py +++ b/apps/unbond.py @@ -16,13 +16,12 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os -import logging import click from bumble.device import Device from bumble.keys import JsonKeyStore from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -68,7 +67,7 @@ def main(keystore_file, hci_transport, device_config, address): instantiated. If no address is passed, the existing pairing keys for all addresses are printed. """ - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() if not keystore_file and not hci_transport: print('either --keystore-file or --hci-transport must be specified.') diff --git a/apps/usb_probe.py b/apps/usb_probe.py index 785b0dd3..acf41fba 100644 --- a/apps/usb_probe.py +++ b/apps/usb_probe.py @@ -26,13 +26,12 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -import os -import logging import click import usb1 from bumble.colors import color from bumble.transport.usb import load_libusb +import bumble.logging # ----------------------------------------------------------------------------- @@ -169,7 +168,7 @@ def is_bluetooth_hci(device): @click.command() @click.option('--verbose', is_flag=True, default=False, help='Print more details') def main(verbose): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper()) + bumble.logging.setup_basic_logging('WARNING') load_libusb() with usb1.USBContext() as context: diff --git a/examples/async_runner.py b/examples/async_runner.py index b29a80f1..92475f9b 100644 --- a/examples/async_runner.py +++ b/examples/async_runner.py @@ -15,11 +15,10 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -import logging import asyncio -import os from bumble.utils import AsyncRunner +import bumble.logging # ----------------------------------------------------------------------------- my_work_queue1 = AsyncRunner.WorkQueue() @@ -83,5 +82,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/battery_client.py b/examples/battery_client.py index e9105dbc..0633e0fa 100644 --- a/examples/battery_client.py +++ b/examples/battery_client.py @@ -17,13 +17,12 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color from bumble.device import Device from bumble.hci import Address from bumble.transport import open_transport from bumble.profiles.battery_service import BatteryServiceProxy +import bumble.logging # ----------------------------------------------------------------------------- @@ -72,5 +71,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/battery_server.py b/examples/battery_server.py index e519d4ed..ea53b01b 100644 --- a/examples/battery_server.py +++ b/examples/battery_server.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging import random import struct @@ -26,6 +24,7 @@ from bumble.core import AdvertisingData from bumble.device import Device from bumble.transport import open_transport from bumble.profiles.battery_service import BatteryService +import bumble.logging # ----------------------------------------------------------------------------- @@ -74,5 +73,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/device_information_client.py b/examples/device_information_client.py index f6d51ba1..8ab31012 100644 --- a/examples/device_information_client.py +++ b/examples/device_information_client.py @@ -17,13 +17,13 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging + from bumble.colors import color from bumble.device import Device, Peer from bumble.hci import Address from bumble.profiles.device_information_service import DeviceInformationServiceProxy from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -116,5 +116,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/device_information_server.py b/examples/device_information_server.py index e51e0698..c7480b36 100644 --- a/examples/device_information_server.py +++ b/examples/device_information_server.py @@ -17,14 +17,13 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging import struct from bumble.core import AdvertisingData from bumble.device import Device from bumble.transport import open_transport from bumble.profiles.device_information_service import DeviceInformationService +import bumble.logging # ----------------------------------------------------------------------------- @@ -70,5 +69,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/heart_rate_client.py b/examples/heart_rate_client.py index ea7bc365..b70d3dc2 100644 --- a/examples/heart_rate_client.py +++ b/examples/heart_rate_client.py @@ -17,13 +17,13 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging + from bumble.colors import color from bumble.device import Device from bumble.hci import Address from bumble.transport import open_transport from bumble.profiles.heart_rate_service import HeartRateServiceProxy +import bumble.logging # ----------------------------------------------------------------------------- @@ -76,5 +76,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/heart_rate_server.py b/examples/heart_rate_server.py index 39471ded..25e0c5b6 100644 --- a/examples/heart_rate_server.py +++ b/examples/heart_rate_server.py @@ -20,9 +20,7 @@ import time import math import random import struct -import logging import asyncio -import os from bumble.core import AdvertisingData from bumble.device import Device @@ -30,6 +28,7 @@ from bumble.transport import open_transport from bumble.profiles.device_information_service import DeviceInformationService from bumble.profiles.heart_rate_service import HeartRateService from bumble.utils import AsyncRunner +import bumble.logging # ----------------------------------------------------------------------------- @@ -128,5 +127,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/keyboard.py b/examples/keyboard.py index 7270fee5..c63f0bda 100644 --- a/examples/keyboard.py +++ b/examples/keyboard.py @@ -17,13 +17,12 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging import struct import json -import websockets -from bumble.colors import color +import websockets + +from bumble.colors import color from bumble.core import AdvertisingData from bumble.device import Device, Connection, Peer from bumble.utils import AsyncRunner @@ -45,6 +44,8 @@ from bumble.gatt import ( GATT_HID_CONTROL_POINT_CHARACTERISTIC, GATT_REPORT_REFERENCE_DESCRIPTOR, ) +import bumble.logging + # ----------------------------------------------------------------------------- @@ -450,5 +451,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_a2dp_info.py b/examples/run_a2dp_info.py index 29f85bb1..fcede377 100644 --- a/examples/run_a2dp_info.py +++ b/examples/run_a2dp_info.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color from bumble.device import Device @@ -39,6 +37,7 @@ from bumble.sdp import ( SDP_BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRIBUTE_ID, SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID, ) +import bumble.logging # ----------------------------------------------------------------------------- @@ -198,5 +197,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_a2dp_sink.py b/examples/run_a2dp_sink.py index 828f02b7..73c2bbb9 100644 --- a/examples/run_a2dp_sink.py +++ b/examples/run_a2dp_sink.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from typing import Any from bumble.device import Device @@ -35,6 +33,8 @@ from bumble.a2dp import ( A2DP_SBC_CODEC_TYPE, SbcMediaCodecInformation, ) +import bumble.logging + Context: dict[Any, Any] = {'output': None} @@ -166,5 +166,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_a2dp_source.py b/examples/run_a2dp_source.py index 40d91c37..19c545be 100644 --- a/examples/run_a2dp_source.py +++ b/examples/run_a2dp_source.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color from bumble.device import Device @@ -38,6 +36,7 @@ from bumble.a2dp import ( SbcMediaCodecInformation, SbcPacketSource, ) +import bumble.logging # ----------------------------------------------------------------------------- @@ -186,5 +185,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_advertiser.py b/examples/run_advertiser.py index 0c28a124..69e23d00 100644 --- a/examples/run_advertiser.py +++ b/examples/run_advertiser.py @@ -16,15 +16,14 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os import struct from bumble.core import AdvertisingData from bumble.device import AdvertisingType, Device from bumble.hci import Address from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -72,5 +71,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_ancs_client.py b/examples/run_ancs_client.py index 2a6aacae..1b2a8951 100644 --- a/examples/run_ancs_client.py +++ b/examples/run_ancs_client.py @@ -17,10 +17,8 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging -from bumble.colors import color +from bumble.colors import color from bumble.device import Device, Peer from bumble.transport import open_transport from bumble.profiles.ancs import ( @@ -31,6 +29,7 @@ from bumble.profiles.ancs import ( Notification, NotificationAttributeId, ) +import bumble.logging # ----------------------------------------------------------------------------- @@ -210,5 +209,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_asha_sink.py b/examples/run_asha_sink.py index 2ffc89e7..b35f63d9 100644 --- a/examples/run_asha_sink.py +++ b/examples/run_asha_sink.py @@ -17,18 +17,19 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os import logging -import websockets - from typing import Optional +import websockets + from bumble import decoder from bumble import gatt from bumble.core import AdvertisingData from bumble.device import Device, AdvertisingParameters from bumble.transport import open_transport from bumble.profiles import asha +import bumble.logging + ws_connection: Optional[websockets.WebSocketServerProtocol] = None g722_decoder = decoder.G722Decoder() @@ -111,9 +112,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig( - level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper(), - format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s', - datefmt='%Y-%m-%d %H:%M:%S', -) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_avrcp.py b/examples/run_avrcp.py index abe2330b..e555189e 100644 --- a/examples/run_avrcp.py +++ b/examples/run_avrcp.py @@ -19,8 +19,8 @@ from __future__ import annotations import asyncio import json import sys -import os import logging + import websockets from bumble.device import Device @@ -31,6 +31,7 @@ from bumble import avrcp from bumble import avdtp from bumble import a2dp from bumble import utils +import bumble.logging logger = logging.getLogger(__name__) @@ -409,5 +410,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_channel_sounding.py b/examples/run_channel_sounding.py index 94a9718b..a84f7a2d 100644 --- a/examples/run_channel_sounding.py +++ b/examples/run_channel_sounding.py @@ -18,15 +18,15 @@ from __future__ import annotations import asyncio -import logging import sys -import os import functools from bumble import core from bumble import hci from bumble.device import Connection, Device, ChannelSoundingCapabilities from bumble.transport import open_transport +import bumble.logging + # From https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/system/gd/hci/distance_measurement_manager.cc. CS_TONE_ANTENNA_CONFIG_MAPPING_TABLE = [ @@ -150,5 +150,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_cig_setup.py b/examples/run_cig_setup.py index 8e0e2f59..67dea204 100644 --- a/examples/run_cig_setup.py +++ b/examples/run_cig_setup.py @@ -16,16 +16,14 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os -from bumble import utils + from bumble.device import Device, CigParameters, CisLink, Connection from bumble.hci import ( OwnAddressType, ) - from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -104,5 +102,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_classic_connect.py b/examples/run_classic_connect.py index 2e67c3d6..b287c120 100644 --- a/examples/run_classic_connect.py +++ b/examples/run_classic_connect.py @@ -17,10 +17,8 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging -from bumble.colors import color +from bumble.colors import color from bumble.device import Device from bumble.transport import open_transport from bumble.core import PhysicalTransport, BT_L2CAP_PROTOCOL_ID, CommandTimeoutError @@ -29,6 +27,7 @@ from bumble.sdp import ( SDP_PUBLIC_BROWSE_ROOT, SDP_ALL_ATTRIBUTES_RANGE, ) +import bumble.logging # ----------------------------------------------------------------------------- @@ -117,5 +116,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_classic_discoverable.py b/examples/run_classic_discoverable.py index d23bc41f..aa09f71e 100644 --- a/examples/run_classic_discoverable.py +++ b/examples/run_classic_discoverable.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.device import Device from bumble.transport import open_transport @@ -38,6 +36,8 @@ from bumble.core import ( BT_AVDTP_PROTOCOL_ID, BT_ADVANCED_AUDIO_DISTRIBUTION_SERVICE, ) +import bumble.logging + # ----------------------------------------------------------------------------- SDP_SERVICE_RECORDS = { @@ -117,5 +117,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_classic_discovery.py b/examples/run_classic_discovery.py index 04d272ea..d60945ed 100644 --- a/examples/run_classic_discovery.py +++ b/examples/run_classic_discovery.py @@ -17,13 +17,13 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging + from bumble.colors import color from bumble.device import Device from bumble.hci import Address from bumble.transport import open_transport from bumble.core import DeviceClass +import bumble.logging # ----------------------------------------------------------------------------- @@ -77,5 +77,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_connect_and_encrypt.py b/examples/run_connect_and_encrypt.py index 03d2d7bf..303a615a 100644 --- a/examples/run_connect_and_encrypt.py +++ b/examples/run_connect_and_encrypt.py @@ -17,11 +17,10 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.device import Device from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -62,5 +61,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_controller.py b/examples/run_controller.py index fc12b6ba..c0e04e83 100644 --- a/examples/run_controller.py +++ b/examples/run_controller.py @@ -15,10 +15,8 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -import logging import asyncio import sys -import os from bumble.gatt import ( GATT_CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR, @@ -33,6 +31,7 @@ from bumble.host import Host from bumble.controller import Controller from bumble.link import LocalLink from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -105,5 +104,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_controller_with_scanner.py b/examples/run_controller_with_scanner.py index 0ba84ef4..98c78fe2 100644 --- a/examples/run_controller_with_scanner.py +++ b/examples/run_controller_with_scanner.py @@ -15,16 +15,16 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -import logging import asyncio import sys -import os + from bumble.colors import color from bumble.device import Device from bumble.controller import Controller from bumble.hci import Address from bumble.link import LocalLink from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -82,5 +82,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_csis_servers.py b/examples/run_csis_servers.py index 44572cc1..147217b5 100644 --- a/examples/run_csis_servers.py +++ b/examples/run_csis_servers.py @@ -16,9 +16,7 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os import secrets from bumble.core import AdvertisingData @@ -28,8 +26,8 @@ from bumble.hci import ( ) from bumble.profiles.cap import CommonAudioServiceService from bumble.profiles.csip import CoordinatedSetIdentificationService, SirkType - from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -101,5 +99,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_device_with_snooper.py b/examples/run_device_with_snooper.py index e4451fd2..d9aaf36a 100644 --- a/examples/run_device_with_snooper.py +++ b/examples/run_device_with_snooper.py @@ -17,12 +17,12 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging + from bumble.hci import Address from bumble.device import Device from bumble.transport import open_transport from bumble.snoop import BtSnooper +import bumble.logging # ----------------------------------------------------------------------------- @@ -52,5 +52,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_esco_connection.py b/examples/run_esco_connection.py index 31e3079b..2ae0bedf 100644 --- a/examples/run_esco_connection.py +++ b/examples/run_esco_connection.py @@ -16,15 +16,14 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os + from bumble.core import PhysicalTransport from bumble.device import Device, ScoLink from bumble.hci import HCI_Enhanced_Setup_Synchronous_Connection_Command from bumble.hfp import DefaultCodecParameters, ESCO_PARAMETERS - from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -83,5 +82,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_extended_advertiser.py b/examples/run_extended_advertiser.py index 8e4d80f7..e0d34c08 100644 --- a/examples/run_extended_advertiser.py +++ b/examples/run_extended_advertiser.py @@ -16,9 +16,8 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os + from bumble.device import ( AdvertisingParameters, AdvertisingEventProperties, @@ -26,8 +25,8 @@ from bumble.device import ( Device, ) from bumble.hci import Address - from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -69,5 +68,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_extended_advertiser_2.py b/examples/run_extended_advertiser_2.py index 24443a21..054f8220 100644 --- a/examples/run_extended_advertiser_2.py +++ b/examples/run_extended_advertiser_2.py @@ -16,13 +16,13 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os + from bumble.device import AdvertisingParameters, AdvertisingEventProperties, Device from bumble.hci import Address from bumble.core import AdvertisingData from bumble.transport import open_transport +import bumble.logging # ----------------------------------------------------------------------------- @@ -96,5 +96,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_gatt_client.py b/examples/run_gatt_client.py index e2af312b..1d5e99fa 100644 --- a/examples/run_gatt_client.py +++ b/examples/run_gatt_client.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color from bumble.core import ProtocolError @@ -26,6 +24,7 @@ from bumble.device import Device, Peer from bumble.gatt import show_services from bumble.transport import open_transport from bumble.utils import AsyncRunner +import bumble.logging # ----------------------------------------------------------------------------- @@ -101,5 +100,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_gatt_client_and_server.py b/examples/run_gatt_client_and_server.py index 0811d748..28ccd43c 100644 --- a/examples/run_gatt_client_and_server.py +++ b/examples/run_gatt_client_and_server.py @@ -16,8 +16,7 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import os -import logging + from bumble.colors import color from bumble.core import ProtocolError from bumble.controller import Controller @@ -34,6 +33,7 @@ from bumble.gatt import ( GATT_DEVICE_INFORMATION_SERVICE, ) from bumble.gatt_client import show_services +import bumble.logging # ----------------------------------------------------------------------------- @@ -119,5 +119,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_gatt_server.py b/examples/run_gatt_server.py index 84937c2f..a3ca1b53 100644 --- a/examples/run_gatt_server.py +++ b/examples/run_gatt_server.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.device import Device, Connection from bumble.transport import open_transport @@ -32,6 +30,7 @@ from bumble.gatt import ( GATT_MANUFACTURER_NAME_STRING_CHARACTERISTIC, GATT_DEVICE_INFORMATION_SERVICE, ) +import bumble.logging # ----------------------------------------------------------------------------- @@ -152,5 +151,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_gatt_server_with_pairing_delegate.py b/examples/run_gatt_server_with_pairing_delegate.py index def8ab6a..bb3f40e8 100644 --- a/examples/run_gatt_server_with_pairing_delegate.py +++ b/examples/run_gatt_server_with_pairing_delegate.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.device import Device from bumble.transport import open_transport @@ -27,6 +25,7 @@ from bumble.gatt import ( Characteristic, ) from bumble.pairing import PairingConfig, PairingDelegate +import bumble.logging # ----------------------------------------------------------------------------- @@ -107,5 +106,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_gatt_with_adapters.py b/examples/run_gatt_with_adapters.py index 18e000a9..c950672e 100644 --- a/examples/run_gatt_with_adapters.py +++ b/examples/run_gatt_with_adapters.py @@ -20,8 +20,6 @@ import asyncio import dataclasses import functools import enum -import logging -import os import random import struct import sys @@ -34,6 +32,7 @@ from bumble import gatt_adapters from bumble import gatt_client from bumble import hci from bumble import core +import bumble.logging # ----------------------------------------------------------------------------- @@ -432,5 +431,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_hap_server.py b/examples/run_hap_server.py index a2739710..08d0579e 100644 --- a/examples/run_hap_server.py +++ b/examples/run_hap_server.py @@ -16,9 +16,7 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os from bumble.core import AdvertisingData from bumble.device import Device @@ -32,8 +30,9 @@ from bumble.profiles.hap import ( WritablePresetsSupport, PresetRecord, ) - from bumble.transport import open_transport +import bumble.logging + server_features = HearingAidFeatures( HearingAidType.MONAURAL_HEARING_AID, @@ -102,5 +101,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_hfp_gateway.py b/examples/run_hfp_gateway.py index 6d08a9b8..4635e8c8 100644 --- a/examples/run_hfp_gateway.py +++ b/examples/run_hfp_gateway.py @@ -18,7 +18,6 @@ import asyncio import json import sys -import os import io import logging from typing import Iterable, Optional @@ -30,6 +29,7 @@ from bumble.device import Device, ScoLink from bumble.transport import open_transport from bumble.core import PhysicalTransport from bumble import hci, rfcomm, hfp +import bumble.logging logger = logging.getLogger(__name__) @@ -286,5 +286,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_hfp_handsfree.py b/examples/run_hfp_handsfree.py index e690e8a4..ddb2075a 100644 --- a/examples/run_hfp_handsfree.py +++ b/examples/run_hfp_handsfree.py @@ -18,20 +18,20 @@ import asyncio import contextlib import sys -import os -import logging import json -import websockets import functools from typing import Optional -from bumble import utils +import websockets + from bumble import rfcomm from bumble import hci from bumble.device import Device, Connection from bumble.transport import open_transport from bumble import hfp from bumble.hfp import HfProtocol +import bumble.logging + ws: Optional[websockets.WebSocketServerProtocol] = None hf_protocol: Optional[HfProtocol] = None @@ -175,5 +175,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_hid_device.py b/examples/run_hid_device.py index e803e7b1..91f5a11d 100644 --- a/examples/run_hid_device.py +++ b/examples/run_hid_device.py @@ -17,12 +17,11 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging import json -import websockets import struct +import websockets + from bumble.device import Device from bumble.transport import open_transport from bumble.core import ( @@ -49,6 +48,8 @@ from bumble.sdp import ( SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID, SDP_BROWSE_GROUP_LIST_ATTRIBUTE_ID, ) +import bumble.logging + # ----------------------------------------------------------------------------- # SDP attributes for Bluetooth HID devices @@ -744,5 +745,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_hid_host.py b/examples/run_hid_host.py index eb09ef1d..9c8593fe 100644 --- a/examples/run_hid_host.py +++ b/examples/run_hid_host.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color @@ -41,6 +39,7 @@ from bumble.sdp import ( SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID, SDP_BROWSE_GROUP_LIST_ATTRIBUTE_ID, ) +import bumble.logging from hid_report_parser import ReportParser # ----------------------------------------------------------------------------- @@ -565,6 +564,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- - -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_mcp_client.py b/examples/run_mcp_client.py index a1702edb..cca063c6 100644 --- a/examples/run_mcp_client.py +++ b/examples/run_mcp_client.py @@ -16,13 +16,12 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os -import websockets import json +from typing import Optional + +import websockets -from bumble import utils from bumble.core import AdvertisingData from bumble.device import ( Device, @@ -53,8 +52,7 @@ from bumble.profiles.mcp import ( ) from bumble.profiles.pacs import PacRecord, PublishedAudioCapabilitiesService from bumble.transport import open_transport - -from typing import Optional +import bumble.logging # ----------------------------------------------------------------------------- @@ -191,5 +189,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_notifier.py b/examples/run_notifier.py index 7f6f4c64..75da4382 100644 --- a/examples/run_notifier.py +++ b/examples/run_notifier.py @@ -17,13 +17,12 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os import random -import logging from bumble.device import Device, Connection from bumble.transport import open_transport from bumble.gatt import Service, Characteristic +import bumble.logging # ----------------------------------------------------------------------------- @@ -128,5 +127,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_rfcomm_client.py b/examples/run_rfcomm_client.py index a0083a8b..97d43d6e 100644 --- a/examples/run_rfcomm_client.py +++ b/examples/run_rfcomm_client.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color @@ -39,6 +37,7 @@ from bumble.sdp import ( SDP_SERVICE_CLASS_ID_LIST_ATTRIBUTE_ID, SDP_BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRIBUTE_ID, ) +import bumble.logging # ----------------------------------------------------------------------------- @@ -237,5 +236,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_rfcomm_server.py b/examples/run_rfcomm_server.py index 483e6b1e..9d23841e 100644 --- a/examples/run_rfcomm_server.py +++ b/examples/run_rfcomm_server.py @@ -17,8 +17,6 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.core import UUID from bumble.device import Device @@ -26,6 +24,7 @@ from bumble.transport import open_transport from bumble.rfcomm import Server from bumble.utils import AsyncRunner from bumble.rfcomm import make_service_sdp_records +import bumble.logging # ----------------------------------------------------------------------------- @@ -159,5 +158,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_scanner.py b/examples/run_scanner.py index 8d689862..4061b6f3 100644 --- a/examples/run_scanner.py +++ b/examples/run_scanner.py @@ -17,12 +17,11 @@ # ----------------------------------------------------------------------------- import asyncio import sys -import os -import logging from bumble.colors import color from bumble.hci import Address from bumble.device import Device from bumble.transport import open_transport +from bumble import logging # ----------------------------------------------------------------------------- @@ -79,5 +78,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_unicast_server.py b/examples/run_unicast_server.py index 78dbe67b..336a9222 100644 --- a/examples/run_unicast_server.py +++ b/examples/run_unicast_server.py @@ -18,9 +18,7 @@ import asyncio import datetime import functools -import logging import sys -import os import io import struct import secrets @@ -46,6 +44,7 @@ from bumble.profiles.cap import CommonAudioServiceService from bumble.profiles.csip import CoordinatedSetIdentificationService, SirkType from bumble.profiles.pacs import PacRecord, PublishedAudioCapabilitiesService from bumble.transport import open_transport +import bumble.logging def _sink_pac_record() -> PacRecord: @@ -200,5 +199,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/examples/run_vcp_renderer.py b/examples/run_vcp_renderer.py index 86596f98..b93e668a 100644 --- a/examples/run_vcp_renderer.py +++ b/examples/run_vcp_renderer.py @@ -16,12 +16,12 @@ # Imports # ----------------------------------------------------------------------------- import asyncio -import logging import sys -import os import secrets -import websockets import json +from typing import Optional + +import websockets from bumble.core import AdvertisingData from bumble.device import Device, AdvertisingParameters, AdvertisingEventProperties @@ -43,10 +43,8 @@ from bumble.profiles.pacs import PacRecord, PublishedAudioCapabilitiesService from bumble.profiles.cap import CommonAudioServiceService from bumble.profiles.csip import CoordinatedSetIdentificationService, SirkType from bumble.profiles.vcs import VolumeControlService - from bumble.transport import open_transport - -from typing import Optional +import bumble.logging def dumps_volume_state(volume_setting: int, muted: int, change_counter: int) -> str: @@ -186,5 +184,5 @@ async def main() -> None: # ----------------------------------------------------------------------------- -logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) +bumble.logging.setup_basic_logging('DEBUG') asyncio.run(main()) diff --git a/tools/intel_util.py b/tools/intel_util.py index 0333a010..8307d4ea 100644 --- a/tools/intel_util.py +++ b/tools/intel_util.py @@ -17,7 +17,6 @@ # ----------------------------------------------------------------------------- import logging import asyncio -import os from typing import Any, Optional import click @@ -26,6 +25,8 @@ from bumble.colors import color from bumble import transport from bumble.drivers import intel from bumble.host import Host +import bumble.logging + # ----------------------------------------------------------------------------- # Logging @@ -107,7 +108,7 @@ async def do_bootloader(usb_transport: str, force: bool) -> None: # ----------------------------------------------------------------------------- @click.group() def main(): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() @main.command diff --git a/tools/rtk_util.py b/tools/rtk_util.py index 8d4b4fa1..3bef487b 100644 --- a/tools/rtk_util.py +++ b/tools/rtk_util.py @@ -15,15 +15,16 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -import logging import asyncio -import os +import logging import click from bumble import transport from bumble.host import Host from bumble.drivers import rtk +import bumble.logging + # ----------------------------------------------------------------------------- # Logging @@ -112,7 +113,7 @@ async def do_info(usb_transport, force): # ----------------------------------------------------------------------------- @click.group() def main(): - logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper()) + bumble.logging.setup_basic_logging() @main.command