Skip to content
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
36 changes: 1 addition & 35 deletions zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import errno
import ipaddress
import itertools
import logging
import platform
import select
import socket
Expand Down Expand Up @@ -100,7 +99,7 @@
NonUniqueNameException,
ServiceNameAlreadyRegistered,
)

from .logger import QuietLogger, log

__author__ = 'Paul Scott-Murphy, William McBrine'
__maintainer__ = 'Jakub Stasiak <jakub@stasiak.at>'
Expand Down Expand Up @@ -129,12 +128,6 @@
'''
)

log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())

if log.level == logging.NOTSET:
log.setLevel(logging.WARN)


int2byte = struct.Struct(">B").pack

Expand Down Expand Up @@ -319,33 +312,6 @@ def instance_name_from_service_info(info: "ServiceInfo") -> str:
# implementation classes


class QuietLogger:
_seen_logs = {} # type: Dict[str, Union[int, tuple]]

@classmethod
def log_exception_warning(cls, *logger_data: Any) -> None:
exc_info = sys.exc_info()
exc_str = str(exc_info[1])
if exc_str not in cls._seen_logs:
# log at warning level the first time this is seen
cls._seen_logs[exc_str] = exc_info
logger = log.warning
else:
logger = log.debug
logger(*(logger_data or ['Exception occurred']), exc_info=True)

@classmethod
def log_warning_once(cls, *args: Any) -> None:
msg_str = args[0]
if msg_str not in cls._seen_logs:
cls._seen_logs[msg_str] = 0
logger = log.warning
else:
logger = log.debug
cls._seen_logs[msg_str] = cast(int, cls._seen_logs[msg_str]) + 1
logger(*args)


class DNSEntry:

"""A DNS entry"""
Expand Down
58 changes: 58 additions & 0 deletions zeroconf/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
""" Multicast DNS Service Discovery for Python, v0.14-wmcbrine
Copyright 2003 Paul Scott-Murphy, 2014 William McBrine

This module provides a framework for the use of DNS Service Discovery
using IP multicast.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
"""

import logging
import sys
from typing import Any, Dict, Union, cast

log = logging.getLogger(__name__.split('.')[0])
log.addHandler(logging.NullHandler())

if log.level == logging.NOTSET:
log.setLevel(logging.WARN)


class QuietLogger:
_seen_logs = {} # type: Dict[str, Union[int, tuple]]

@classmethod
def log_exception_warning(cls, *logger_data: Any) -> None:
exc_info = sys.exc_info()
exc_str = str(exc_info[1])
if exc_str not in cls._seen_logs:
# log at warning level the first time this is seen
cls._seen_logs[exc_str] = exc_info
logger = log.warning
else:
logger = log.debug
logger(*(logger_data or ['Exception occurred']), exc_info=True)

@classmethod
def log_warning_once(cls, *args: Any) -> None:
msg_str = args[0]
if msg_str not in cls._seen_logs:
cls._seen_logs[msg_str] = 0
logger = log.warning
else:
logger = log.debug
cls._seen_logs[msg_str] = cast(int, cls._seen_logs[msg_str]) + 1
logger(*args)