From d611d2580214f7606cf556677237229bc33b10da Mon Sep 17 00:00:00 2001 From: Gilles Boccon-Gibod Date: Sat, 26 Jul 2025 21:20:52 -0700 Subject: [PATCH 1/2] resolve merge conflicts --- .vscode/settings.json | 4 +++- apps/auracast.py | 5 +++-- apps/bench.py | 8 ++------ apps/controller_info.py | 9 ++------- apps/controller_loopback.py | 14 +++++--------- apps/controllers.py | 5 ++--- apps/device_info.py | 5 ++--- apps/gatt_dump.py | 6 +++--- apps/gg_bridge.py | 6 +++--- apps/hci_bridge.py | 5 +++-- apps/l2cap_bridge.py | 6 +++--- apps/lea_unicast/app.py | 4 ++-- apps/player/player.py | 5 ++--- apps/rfcomm_bridge.py | 5 ++--- apps/scan.py | 5 ++--- apps/show.py | 4 ++-- apps/speaker/speaker.py | 8 ++------ apps/unbond.py | 5 ++--- apps/usb_probe.py | 5 ++--- examples/async_runner.py | 5 ++--- examples/battery_client.py | 5 ++--- examples/battery_server.py | 5 ++--- examples/device_information_client.py | 6 +++--- examples/device_information_server.py | 5 ++--- examples/heart_rate_client.py | 6 +++--- examples/heart_rate_server.py | 5 ++--- examples/keyboard.py | 11 ++++++----- examples/run_a2dp_info.py | 5 ++--- examples/run_a2dp_sink.py | 6 +++--- examples/run_a2dp_source.py | 5 ++--- examples/run_advertiser.py | 5 ++--- examples/run_ancs_client.py | 7 +++---- examples/run_asha_sink.py | 13 +++++-------- examples/run_avrcp.py | 5 +++-- examples/run_channel_sounding.py | 6 +++--- examples/run_cig_setup.py | 8 +++----- examples/run_classic_connect.py | 7 +++---- examples/run_classic_discoverable.py | 6 +++--- examples/run_classic_discovery.py | 6 +++--- examples/run_connect_and_encrypt.py | 5 ++--- examples/run_controller.py | 5 ++--- examples/run_controller_with_scanner.py | 6 +++--- examples/run_csis_servers.py | 6 ++---- examples/run_device_with_snooper.py | 6 +++--- examples/run_esco_connection.py | 7 +++---- examples/run_extended_advertiser.py | 7 +++---- examples/run_extended_advertiser_2.py | 6 +++--- examples/run_gatt_client.py | 5 ++--- examples/run_gatt_client_and_server.py | 6 +++--- examples/run_gatt_server.py | 5 ++--- examples/run_gatt_server_with_pairing_delegate.py | 5 ++--- examples/run_gatt_with_adapters.py | 5 ++--- examples/run_hap_server.py | 7 +++---- examples/run_hfp_gateway.py | 4 ++-- examples/run_hfp_handsfree.py | 10 +++++----- examples/run_hid_device.py | 9 +++++---- examples/run_hid_host.py | 6 ++---- examples/run_mcp_client.py | 12 +++++------- examples/run_notifier.py | 5 ++--- examples/run_rfcomm_client.py | 5 ++--- examples/run_rfcomm_server.py | 5 ++--- examples/run_scanner.py | 5 ++--- examples/run_unicast_server.py | 5 ++--- examples/run_vcp_renderer.py | 12 +++++------- tools/intel_util.py | 5 +++-- tools/rtk_util.py | 7 ++++--- 66 files changed, 180 insertions(+), 232 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e0ff04e..c6696ab 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 2fd930d..5dbcbb7 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 e0df336..d7e9fcd 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 efda714..f71b178 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 a2bdffe..22a7502 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 09974a8..4584aab 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 979546d..fb860ec 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 c09dc8a..5633edf 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 9fb27de..f8526b2 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 883166c..18f069e 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 89d3a14..7ca3146 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 79975de..0ffb9da 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 448b8cc..f1454c1 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 5946b10..90a0824 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 9de272d..7d1fc9b 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 64cd0a0..1a443dc 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 e083c88..b4f206b 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 01cb9e5..acef475 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 785b0dd..acf41fb 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 b29a80f..92475f9 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 e9105db..0633e0f 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 e519d4e..ea53b01 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 f6d51ba..8ab3101 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 e51e069..c7480b3 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 ea7bc36..b70d3dc 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 39471de..25e0c5b 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 7270fee..c63f0bd 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 29f85bb..fcede37 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 828f02b..73c2bbb 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 40d91c3..19c545b 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 0c28a12..69e23d0 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 2a6aaca..1b2a895 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 2ffc89e..b35f63d 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 abe2330..e555189 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 94a9718..a84f7a2 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 8e0e2f5..67dea20 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 2e67c3d..b287c12 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 d23bc41..aa09f71 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 04d272e..d60945e 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 03d2d7b..303a615 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 fc12b6b..c0e04e8 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 0ba84ef..98c78fe 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 44572cc..147217b 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 e4451fd..d9aaf36 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 31e3079..2ae0bed 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 8e4d80f..e0d34c0 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 24443a2..054f822 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 e2af312..1d5e99f 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 0811d74..28ccd43 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 84937c2..a3ca1b5 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 def8ab6..bb3f40e 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 18e000a..c950672 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 a273971..08d0579 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 6d08a9b..4635e8c 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 e690e8a..ddb2075 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 e803e7b..91f5a11 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 eb09ef1..9c8593f 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 a1702ed..cca063c 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 7f6f4c6..75da438 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 a0083a8..97d43d6 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 483e6b1..9d23841 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 8d68986..4061b6f 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 78dbe67..336a922 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 86596f9..b93e668 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 0333a01..8307d4e 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 8d4b4fa..3bef487 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 From b8b78ca1ee0545442943864e3eefb48aee94f41e Mon Sep 17 00:00:00 2001 From: Gilles Boccon-Gibod Date: Sun, 27 Jul 2025 15:02:42 -0700 Subject: [PATCH 2/2] add missing file --- bumble/logging.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bumble/logging.py diff --git a/bumble/logging.py b/bumble/logging.py new file mode 100644 index 0000000..3f93756 --- /dev/null +++ b/bumble/logging.py @@ -0,0 +1,65 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# ----------------------------------------------------------------------------- +# Imports +# ----------------------------------------------------------------------------- +import functools +import logging +import os + +from bumble import colors + + +# ----------------------------------------------------------------------------- +class ColorFormatter(logging.Formatter): + _colorizers = { + logging.DEBUG: functools.partial(colors.color, fg="white"), + logging.INFO: functools.partial(colors.color, fg="green"), + logging.WARNING: functools.partial(colors.color, fg="yellow"), + logging.ERROR: functools.partial(colors.color, fg="red"), + logging.CRITICAL: functools.partial(colors.color, fg="black", bg="red"), + } + + _formatters = { + level: logging.Formatter( + fmt=colorizer("{asctime}.{msecs:03.0f} {levelname:.1} {name}: ") + + "{message}", + datefmt="%H:%M:%S", + style="{", + ) + for level, colorizer in _colorizers.items() + } + + def format(self, record: logging.LogRecord) -> str: + return self._formatters[record.levelno].format(record) + + +def setup_basic_logging(default_level: str = "INFO") -> None: + """ + Set up basic logging with logging.basicConfig, configured with a simple formatter + that prints out the date and log level in color. + If the BUMBLE_LOGLEVEL environment variable is set to the name of a log level, it + is used. Otherwise the default_level argument is used. + + Args: + default_level: default logging level + + """ + handler = logging.StreamHandler() + handler.setFormatter(ColorFormatter()) + logging.basicConfig( + level=os.environ.get("BUMBLE_LOGLEVEL", default_level).upper(), + handlers=[handler], + )