Skip to content

Commit

Permalink
fix: add logger to print some debug log to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
tybalex committed Mar 5, 2025
1 parent b6bea6b commit 5b3cdd2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
33 changes: 33 additions & 0 deletions zoom/tools/helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import logging
import sys

ACCESS_TOKEN = os.getenv("ZOOM_OAUTH_TOKEN")

Expand All @@ -8,6 +10,37 @@
ZOOM_API_URL = "https://api.zoom.us/v2"


def setup_logger(name):
"""Setup a logger that writes to sys.stderr. This will eventually show up in GPTScript's debugging logs.
Args:
name (str): The name of the logger.
Returns:
logging.Logger: The logger.
"""
# Create a logger
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG) # Set the logging level

# Create a stream handler that writes to sys.stderr
stderr_handler = logging.StreamHandler(sys.stderr)

# Create a log formatter
formatter = logging.Formatter(
"[WordPress Tool Debugging Log]: %(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
stderr_handler.setFormatter(formatter)

# Add the handler to the logger
logger.addHandler(stderr_handler)

return logger


logger = setup_logger(__name__)


def str_to_bool(value):
"""Convert a string to a boolean."""
return str(value).lower() in ("true", "1", "yes")
Expand Down
24 changes: 21 additions & 3 deletions zoom/tools/meetings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from tools.helper import ZOOM_API_URL, ACCESS_TOKEN, str_to_bool, tool_registry
from tools.helper import (
ZOOM_API_URL,
ACCESS_TOKEN,
str_to_bool,
tool_registry,
setup_logger,
)
from tools.users import get_user_type
import requests
import os
Expand All @@ -9,6 +15,8 @@
from zoneinfo import ZoneInfo
import json

logger = setup_logger(__name__)


def _convert_utc_to_local_time(utc_time_str: str, timezone: str) -> str:
try:
Expand All @@ -27,6 +35,7 @@ def _convert_utc_to_local_time(utc_time_str: str, timezone: str) -> str:
) # Customize format as necessary
return output_gmt_format
except Exception as e:
logger.error(f"Error converting time: {e}")
raise ValueError(f"Error converting time: {e}")


Expand All @@ -50,7 +59,10 @@ def _validate_meeting_start_time(input_time: str) -> bool:
local_format = r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$"

# Validate against both formats
return bool(re.match(gmt_format, input_time) or re.match(local_format, input_time))
res = bool(re.match(gmt_format, input_time) or re.match(local_format, input_time))
if res == False: # invalid time format
logger.error(f"Invalid input time format: {input_time}")
return res


def _validate_invitees(invitees: list) -> bool:
Expand Down Expand Up @@ -101,6 +113,9 @@ def create_meeting():
"MEETING_INVITEES", ""
) # a list of emails separated by commas
if meeting_invitees != "" and not _validate_invitees(meeting_invitees.split(",")):
logger.error(
f"Invalid invitees: {meeting_invitees}. Must be a list of valid email addresses separated by commas."
)
raise ValueError(
f"Invalid invitees: {meeting_invitees}. Must be a list of valid email addresses separated by commas."
)
Expand Down Expand Up @@ -207,8 +222,11 @@ def create_meeting():
recurrence_object = json.loads(recurrence)
payload["recurrence"] = recurrence_object
except Exception as e:
logger.error(
f"Exception {e}: Invalid recurrence: {recurrence}. Must be a valid JSON object."
)
raise ValueError(
f"Invalid recurrence: {recurrence}. Must be a valid JSON object."
f"Exception {e}: Invalid recurrence: {recurrence}. Must be a valid JSON object."
)
# features for licensed users
if user_type == 2:
Expand Down

0 comments on commit 5b3cdd2

Please sign in to comment.