mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-05 01:00:23 +02:00
scratch_link.py: Add debug print option
In the GitHub issue "Scratux support #9", debug message log was required for analysis. However, script edit by users was required to enable debug print. This is not handy. To avoid that the chore by users, add -d debug print option. Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
This commit is contained in:
@@ -10,6 +10,8 @@ import ssl
|
||||
import websockets
|
||||
import json
|
||||
import base64
|
||||
import logging
|
||||
import sys
|
||||
|
||||
# for Bluetooth (e.g. Lego EV3)
|
||||
import bluetooth
|
||||
@@ -21,12 +23,26 @@ from bluepy.btle import BTLEDisconnectError, BTLEManagementError
|
||||
import threading
|
||||
import time
|
||||
|
||||
logLevel = logging.INFO
|
||||
|
||||
# handle command line options
|
||||
if __name__ == "__main__":
|
||||
opts = [opt for opt in sys.argv[1:] if opt.startswith("-")]
|
||||
if "-h" in opts:
|
||||
print((f"Usage: {sys.argv[0]} [OPTS]\n"
|
||||
"OPTS:\t-h Show this help.\n"
|
||||
"\t-d Print debug messages."
|
||||
))
|
||||
sys.exit(1)
|
||||
elif "-d" in opts:
|
||||
print("Print debug messages")
|
||||
logLevel = logging.DEBUG
|
||||
|
||||
# for logging
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.INFO)
|
||||
logger.setLevel(logging.INFO)
|
||||
handler.setLevel(logLevel)
|
||||
logger.setLevel(logLevel)
|
||||
logger.addHandler(handler)
|
||||
logger.propagate = False
|
||||
|
||||
|
Reference in New Issue
Block a user