Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve logging in example scripts #839

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/bbciplayer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import pychromecast
from pychromecast import quick_play

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

# Change to the name of your Chromecast
CAST_NAME = "Lounge Video"

Expand Down Expand Up @@ -42,6 +48,9 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -60,7 +69,14 @@
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
18 changes: 17 additions & 1 deletion examples/bbcsounds_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import pychromecast
from pychromecast import quick_play

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

# Change to the name of your Chromecast
CAST_NAME = "Lounge Video"

Expand Down Expand Up @@ -49,6 +55,9 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -71,7 +80,14 @@
args.is_live = DEFAULT_MEDIA_ID_IS_LIVE

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
18 changes: 17 additions & 1 deletion examples/bubbleupnp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
from pychromecast import quick_play


# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

# Change to the friendly name of your Chromecast
CAST_NAME = "Kitchen speaker"

Expand All @@ -36,6 +42,9 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -48,7 +57,14 @@
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
18 changes: 17 additions & 1 deletion examples/dashcast_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import pychromecast
from pychromecast.controllers import dashcast

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

# Change to the friendly name of your Chromecast
CAST_NAME = "Living Room"

Expand All @@ -28,13 +34,23 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
17 changes: 16 additions & 1 deletion examples/default_media_receiver_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import pychromecast
from pychromecast import quick_play

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

# Change to the friendly name of your Chromecast
CAST_NAME = "Kitchen speaker"
Expand All @@ -35,6 +40,9 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -44,7 +52,14 @@
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
19 changes: 18 additions & 1 deletion examples/discovery_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import logging
import sys
import time
from uuid import UUID

Expand All @@ -13,6 +14,12 @@
import pychromecast
from pychromecast import CastInfo

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

parser = argparse.ArgumentParser(
description="Example on how to receive updates on discovered chromecasts."
)
Expand All @@ -27,6 +34,9 @@
action="store_true",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -36,7 +46,14 @@
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
19 changes: 18 additions & 1 deletion examples/discovery_example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@

import argparse
import logging
import sys

import zeroconf

import pychromecast

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

parser = argparse.ArgumentParser(
description="Example that shows how to list all available chromecasts."
)
Expand All @@ -19,6 +26,9 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -28,7 +38,14 @@
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
18 changes: 17 additions & 1 deletion examples/discovery_example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

import pychromecast

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

parser = argparse.ArgumentParser(
description="Example that shows how to list chromecasts matching on name or uuid."
)
Expand All @@ -23,6 +29,9 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
Expand All @@ -32,7 +41,14 @@
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
18 changes: 17 additions & 1 deletion examples/get_chromecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

import pychromecast

# Enable deprecation warnings etc.
if not sys.warnoptions:
import warnings

warnings.simplefilter("default")

parser = argparse.ArgumentParser(
description="Example on how to connect to all chromecasts."
)
Expand All @@ -20,13 +26,23 @@
action="append",
)
parser.add_argument("--show-debug", help="Enable debug log", action="store_true")
parser.add_argument(
"--show-discovery-debug", help="Enable discovery debug log", action="store_true"
)
parser.add_argument(
"--show-zeroconf-debug", help="Enable zeroconf debug log", action="store_true"
)
args = parser.parse_args()

if args.show_debug:
logging.basicConfig(level=logging.DEBUG)
fmt = "%(asctime)s %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG)
logging.getLogger("pychromecast.dial").setLevel(logging.INFO)
logging.getLogger("pychromecast.discovery").setLevel(logging.INFO)
if args.show_discovery_debug:
logging.getLogger("pychromecast.dial").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.discovery").setLevel(logging.DEBUG)
if args.show_zeroconf_debug:
print("Zeroconf version: " + zeroconf.__version__)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)
Expand Down
Loading