Skip to content

logging_utils

Logging Utilities for Pushover Variables

format_log_string(response) #

Generate a formatted string for logging

Parameters:

Name Type Description Default
response Union[CampgroundFacility, RecreationArea, str]
required

Returns:

Type Description
str
Source code in camply/utils/logging_utils.py
def format_log_string(response: Union[CampgroundFacility, RecreationArea, str]) -> str:
    """
    Generate a formatted string for logging

    Parameters
    ----------
    response: Union[CampgroundFacility]

    Returns
    -------
    str
    """
    if isinstance(response, CampgroundFacility):
        if isinstance(response.facility_id, int):
            facil = f"#{response.facility_id}"
        else:
            facil = response.facility_id
        return (
            f"⛰  {response.recreation_area} (#{response.recreation_area_id}) - "
            f"🏕  {response.facility_name} ({facil})"
        )
    elif isinstance(response, RecreationArea):
        return (
            f"⛰  {response.recreation_area}, {response.recreation_area_location} "
            f"(#{response.recreation_area_id})"
        )
    elif isinstance(response, GoingToCampEquipment):
        return f"{RVMOJI} {response.equipment_name} " f"(#{response.equipment_type_id})"
    elif isinstance(response, str):
        return response
    else:
        raise NotImplementedError

get_emoji(obj) #

Return the Right Emoji

Parameters:

Name Type Description Default
obj list
required

Returns:

Type Description
str
Source code in camply/utils/logging_utils.py
def get_emoji(obj: list) -> str:
    """
    Return the Right Emoji

    Parameters
    ----------
    obj: list

    Returns
    -------
    str
    """
    assert isinstance(obj, list)
    if len(obj) >= 1:
        return TENTMOJI
    else:
        return XMOJI

log_camply(self, message, *args, **kwargs) #

Custom Logging Notification Level for Pushover Logging

Between logging.ERROR and logging.CRITICAL (45)

Parameters:

Name Type Description Default
self Logger
required
message str

Message String

required
args
()
kwargs
{}

Returns:

Type Description
None
Source code in camply/utils/logging_utils.py
def log_camply(self: logging.Logger, message: str, *args, **kwargs) -> None:
    """
    Custom Logging Notification Level for Pushover Logging

    Between logging.ERROR and logging.CRITICAL (45)

    Parameters
    ----------
    self: logging.Logger
    message: str
        Message String
    args
    kwargs

    Returns
    -------
    None
    """
    notification_level = logging.INFO + 1
    logging.addLevelName(level=notification_level, levelName="CAMPLY")
    if self.isEnabledFor(level=notification_level):
        self._log(level=notification_level, msg=message, args=args, **kwargs)

log_sorted_response(response_array) #

Log Some Statements in a Nice Sorted way

Parameters:

Name Type Description Default
response_array List[Any]
required

Returns:

Type Description
None
Source code in camply/utils/logging_utils.py
def log_sorted_response(response_array: List[Any]) -> None:
    """
    Log Some Statements in a Nice Sorted way

    Parameters
    ----------
    response_array: List[str]

    Returns
    -------
    None
    """
    log_array = [format_log_string(obj) for obj in response_array]
    sorted_logs = sorted(log_array)
    for log_response in sorted_logs:
        logger.info(log_response)