Add some missing logging features (#5388)

This commit is contained in:
spaghEddieDoyle
2021-05-11 01:52:40 -07:00
committed by GitHub
parent dd73f117f0
commit 4c72f7f268
3 changed files with 229 additions and 73 deletions

View File

@@ -5,9 +5,9 @@ from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequenc
from string import Template
from time import struct_time
from types import FrameType, TracebackType
from typing import IO, Any, ClassVar, Optional, Tuple, Type, Union
from typing import IO, Any, ClassVar, Optional, Pattern, Tuple, Type, Union
_SysExcInfoType = Union[Tuple[type, BaseException, Optional[TracebackType]], Tuple[None, None, None]]
_SysExcInfoType = Union[Tuple[Type[BaseException], BaseException, Optional[TracebackType]], Tuple[None, None, None]]
_ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException]
_ArgsType = Union[Tuple[Any, ...], Mapping[str, Any]]
_FilterType = Union[Filter, Callable[[LogRecord], int]]
@@ -31,7 +31,7 @@ class Filterer(object):
def removeFilter(self, filter: _FilterType) -> None: ...
def filter(self, record: LogRecord) -> bool: ...
class Manager(object):
class Manager(object): # undocumented
root: RootLogger
disable: int
emittedNoHandlerWarning: bool
@@ -44,14 +44,14 @@ class Manager(object):
def setLogRecordFactory(self, factory: Callable[..., LogRecord]) -> None: ...
class Logger(Filterer):
name: str
level: int
parent: Union[Logger, PlaceHolder]
name: str # undocumented
level: int # undocumented
parent: Optional[Logger] # undocumented
propagate: bool
handlers: list[Handler]
disabled: int
handlers: list[Handler] # undocumented
disabled: bool # undocumented
root: ClassVar[RootLogger] # undocumented
manager: ClassVar[Manager] # undocumented
manager: Manager # undocumented
def __init__(self, name: str, level: _Level = ...) -> None: ...
def setLevel(self, level: _Level) -> None: ...
def isEnabledFor(self, level: int) -> bool: ...
@@ -204,7 +204,6 @@ class Logger(Filterer):
extra: Optional[dict[str, Any]] = ...,
**kwargs: Any,
) -> None: ...
fatal = critical
def log(
self,
level: int,
@@ -233,6 +232,7 @@ class Logger(Filterer):
extra: Optional[dict[str, Any]] = ...,
stack_info: bool = ...,
) -> None: ... # undocumented
fatal = critical
def filter(self, record: LogRecord) -> bool: ...
def addHandler(self, hdlr: Handler) -> None: ...
def removeHandler(self, hdlr: Handler) -> None: ...
@@ -255,6 +255,7 @@ class Logger(Filterer):
sinfo: Optional[str] = ...,
) -> LogRecord: ...
def hasHandlers(self) -> bool: ...
def callHandlers(self, record: LogRecord) -> None: ... # undocumented
CRITICAL: int
FATAL: int
@@ -271,26 +272,31 @@ class Handler(Filterer):
lock: Optional[threading.Lock] # undocumented
name: Optional[str] # undocumented
def __init__(self, level: _Level = ...) -> None: ...
def get_name(self) -> str: ... # undocumented
def set_name(self, name: str) -> None: ... # undocumented
def createLock(self) -> None: ...
def acquire(self) -> None: ...
def release(self) -> None: ...
def setLevel(self, level: _Level) -> None: ...
def setFormatter(self, fmt: Formatter) -> None: ...
def setFormatter(self, fmt: Optional[Formatter]) -> None: ...
def filter(self, record: LogRecord) -> bool: ...
def flush(self) -> None: ...
def close(self) -> None: ...
def handle(self, record: LogRecord) -> None: ...
def handle(self, record: LogRecord) -> bool: ...
def handleError(self, record: LogRecord) -> None: ...
def format(self, record: LogRecord) -> str: ...
def emit(self, record: LogRecord) -> None: ...
class Formatter:
converter: Callable[[Optional[float]], struct_time]
_fmt: Optional[str]
datefmt: Optional[str]
_style: PercentStyle
_fmt: Optional[str] # undocumented
datefmt: Optional[str] # undocumented
_style: PercentStyle # undocumented
default_time_format: str
default_msec_format: str
if sys.version_info >= (3, 9):
default_msec_format: Optional[str]
else:
default_msec_format: str
if sys.version_info >= (3, 8):
def __init__(
@@ -303,15 +309,25 @@ class Formatter:
def formatException(self, ei: _SysExcInfoType) -> str: ...
def formatMessage(self, record: LogRecord) -> str: ... # undocumented
def formatStack(self, stack_info: str) -> str: ...
def usesTime(self) -> bool: ... # undocumented
class BufferingFormatter:
linefmt: Formatter
def __init__(self, linefmt: Optional[Formatter] = ...) -> None: ...
def formatHeader(self, records: Sequence[LogRecord]) -> str: ...
def formatFooter(self, records: Sequence[LogRecord]) -> str: ...
def format(self, records: Sequence[LogRecord]) -> str: ...
class Filter:
name: str # undocumented
nlen: int # undocumented
def __init__(self, name: str = ...) -> None: ...
def filter(self, record: LogRecord) -> bool: ...
class LogRecord:
args: _ArgsType
asctime: str
created: int
created: float
exc_info: Optional[_SysExcInfoType]
exc_text: Optional[str]
filename: str
@@ -320,17 +336,17 @@ class LogRecord:
levelno: int
lineno: int
module: str
msecs: int
msecs: float
message: str
msg: str
name: str
pathname: str
process: int
processName: str
relativeCreated: int
process: Optional[int]
processName: Optional[str]
relativeCreated: float
stack_info: Optional[str]
thread: int
threadName: str
thread: Optional[int]
threadName: Optional[str]
def __init__(
self,
name: str,
@@ -347,8 +363,13 @@ class LogRecord:
class LoggerAdapter:
logger: Logger
extra: Mapping[str, Any]
def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ...
manager: Manager # undocumented
if sys.version_info >= (3, 10):
extra: Optional[Mapping[str, Any]]
def __init__(self, logger: Logger, extra: Optional[Mapping[str, Any]]) -> None: ...
else:
extra: Mapping[str, Any]
def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ...
def process(self, msg: Any, kwargs: MutableMapping[str, Any]) -> tuple[Any, MutableMapping[str, Any]]: ...
if sys.version_info >= (3, 8):
def debug(
@@ -508,7 +529,7 @@ class LoggerAdapter:
) -> None: ...
def isEnabledFor(self, level: int) -> bool: ...
def getEffectiveLevel(self) -> int: ...
def setLevel(self, level: Union[int, str]) -> None: ...
def setLevel(self, level: _Level) -> None: ...
def hasHandlers(self) -> bool: ...
def _log(
self,
@@ -519,9 +540,11 @@ class LoggerAdapter:
extra: Optional[dict[str, Any]] = ...,
stack_info: bool = ...,
) -> None: ... # undocumented
@property
def name(self) -> str: ... # undocumented
def getLogger(name: Optional[str] = ...) -> Logger: ...
def getLoggerClass() -> type: ...
def getLoggerClass() -> Type[Logger]: ...
def getLogRecordFactory() -> Callable[..., LogRecord]: ...
if sys.version_info >= (3, 8):
@@ -675,7 +698,7 @@ else:
def disable(level: int) -> None: ...
def addLevelName(level: int, levelName: str) -> None: ...
def getLevelName(level: Union[int, str]) -> Any: ...
def getLevelName(level: _Level) -> Any: ...
def makeLogRecord(dict: Mapping[str, Any]) -> LogRecord: ...
if sys.version_info >= (3, 8):
@@ -724,12 +747,24 @@ class FileHandler(StreamHandler):
mode: str # undocumented
encoding: Optional[str] # undocumented
delay: bool # undocumented
def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ...
if sys.version_info >= (3, 9):
errors: Optional[str] # undocumented
def __init__(
self,
filename: StrPath,
mode: str = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
errors: Optional[str] = ...,
) -> None: ...
else:
def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ...
def _open(self) -> IO[Any]: ...
class NullHandler(Handler): ...
class PlaceHolder:
class PlaceHolder: # undocumented
loggerMap: dict[Logger, None]
def __init__(self, alogger: Logger) -> None: ...
def append(self, alogger: Logger) -> None: ...
@@ -740,18 +775,24 @@ class RootLogger(Logger):
root: RootLogger
class PercentStyle(object):
class PercentStyle(object): # undocumented
default_format: str
asctime_format: str
asctime_search: str
if sys.version_info >= (3, 8):
validation_pattern: Pattern[str]
_fmt: str
def __init__(self, fmt: str) -> None: ...
def usesTime(self) -> bool: ...
if sys.version_info >= (3, 8):
def validate(self) -> None: ...
def format(self, record: Any) -> str: ...
class StrFormatStyle(PercentStyle): ...
class StrFormatStyle(PercentStyle): # undocumented
fmt_spec = Any
field_spec = Any
class StringTemplateStyle(PercentStyle):
class StringTemplateStyle(PercentStyle): # undocumented
_tpl: Template
_STYLES: dict[str, tuple[PercentStyle, str]]

View File

@@ -3,16 +3,39 @@ from _typeshed import AnyPath, StrPath
from collections.abc import Callable
from configparser import RawConfigParser
from threading import Thread
from typing import IO, Any, Optional, Union
from typing import IO, Any, Optional, Pattern, Union
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
if sys.version_info >= (3, 7):
_Path = AnyPath
else:
_Path = StrPath
DEFAULT_LOGGING_CONFIG_PORT: int
RESET_ERROR: int # undocumented
IDENTIFIER: Pattern[str] # undocumented
def dictConfig(config: dict[str, Any]) -> None: ...
def fileConfig(
fname: Union[_Path, IO[str], RawConfigParser], defaults: Optional[dict[str, str]] = ..., disable_existing_loggers: bool = ...
) -> None: ...
if sys.version_info >= (3, 10):
def fileConfig(
fname: Union[_Path, IO[str], RawConfigParser],
defaults: Optional[dict[str, str]] = ...,
disable_existing_loggers: bool = ...,
encoding: Optional[str] = ...,
) -> None: ...
else:
def fileConfig(
fname: Union[_Path, IO[str], RawConfigParser],
defaults: Optional[dict[str, str]] = ...,
disable_existing_loggers: bool = ...,
) -> None: ...
def valid_ident(s: str) -> Literal[True]: ... # undocumented
def listen(port: int = ..., verify: Optional[Callable[[bytes], Optional[bytes]]] = ...) -> Thread: ...
def stopListening() -> None: ...

View File

@@ -1,11 +1,12 @@
import datetime
import http.client
import ssl
import sys
from _typeshed import StrPath
from collections.abc import Callable
from logging import FileHandler, Handler, LogRecord
from socket import SocketKind, SocketType
from typing import Any, ClassVar, Optional, Union
from typing import Any, ClassVar, Optional, Pattern, Union
if sys.version_info >= (3, 7):
from queue import Queue, SimpleQueue
@@ -20,49 +21,111 @@ SYSLOG_UDP_PORT: int
SYSLOG_TCP_PORT: int
class WatchedFileHandler(FileHandler):
dev: int
ino: int
def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ...
def _statstream(self) -> None: ...
dev: int # undocumented
ino: int # undocumented
if sys.version_info >= (3, 9):
def __init__(
self,
filename: StrPath,
mode: str = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
errors: Optional[str] = ...,
) -> None: ...
else:
def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ...
def _statstream(self) -> None: ... # undocumented
def reopenIfNeeded(self) -> None: ...
class BaseRotatingHandler(FileHandler):
terminator: str
namer: Optional[Callable[[str], str]]
rotator: Optional[Callable[[str, str], None]]
def __init__(self, filename: StrPath, mode: str, encoding: Optional[str] = ..., delay: bool = ...) -> None: ...
def rotation_filename(self, default_name: str) -> None: ...
if sys.version_info >= (3, 9):
def __init__(
self, filename: StrPath, mode: str, encoding: Optional[str] = ..., delay: bool = ..., errors: Optional[str] = ...
) -> None: ...
else:
def __init__(self, filename: StrPath, mode: str, encoding: Optional[str] = ..., delay: bool = ...) -> None: ...
def rotation_filename(self, default_name: str) -> str: ...
def rotate(self, source: str, dest: str) -> None: ...
class RotatingFileHandler(BaseRotatingHandler):
def __init__(
self,
filename: StrPath,
mode: str = ...,
maxBytes: int = ...,
backupCount: int = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
) -> None: ...
maxBytes: str # undocumented
backupCount: str # undocumented
if sys.version_info >= (3, 9):
def __init__(
self,
filename: StrPath,
mode: str = ...,
maxBytes: int = ...,
backupCount: int = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
errors: Optional[str] = ...,
) -> None: ...
else:
def __init__(
self,
filename: StrPath,
mode: str = ...,
maxBytes: int = ...,
backupCount: int = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
) -> None: ...
def doRollover(self) -> None: ...
def shouldRollover(self, record: LogRecord) -> int: ... # undocumented
class TimedRotatingFileHandler(BaseRotatingHandler):
def __init__(
self,
filename: StrPath,
when: str = ...,
interval: int = ...,
backupCount: int = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
utc: bool = ...,
atTime: Optional[datetime.datetime] = ...,
) -> None: ...
when: str # undocumented
backupCount: str # undocumented
utc: bool # undocumented
atTime: Optional[datetime.datetime] # undocumented
interval: int # undocumented
suffix: str # undocumented
dayOfWeek: int # undocumented
rolloverAt: int # undocumented
extMatch: Pattern[str] # undocumented
if sys.version_info >= (3, 9):
def __init__(
self,
filename: StrPath,
when: str = ...,
interval: int = ...,
backupCount: int = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
utc: bool = ...,
atTime: Optional[datetime.datetime] = ...,
errors: Optional[str] = ...,
) -> None: ...
else:
def __init__(
self,
filename: StrPath,
when: str = ...,
interval: int = ...,
backupCount: int = ...,
encoding: Optional[str] = ...,
delay: bool = ...,
utc: bool = ...,
atTime: Optional[datetime.datetime] = ...,
) -> None: ...
def doRollover(self) -> None: ...
def shouldRollover(self, record: LogRecord) -> int: ... # undocumented
def computeRollover(self, currentTime: int) -> int: ... # undocumented
def getFilesToDelete(self) -> list[str]: ... # undocumented
class SocketHandler(Handler):
retryStart: float
retryFactor: float
retryMax: float
host: str # undocumented
port: Optional[int] # undocumented
address: Union[tuple[str, int], str] # undocumented
sock: Optional[SocketType] # undocumented
closeOnError: bool # undocumented
retryTime: Optional[float] # undocumented
retryStart: float # undocumented
retryFactor: float # undocumented
retryMax: float # undocumented
def __init__(self, host: str, port: Optional[int]) -> None: ...
def makeSocket(self, timeout: float = ...) -> SocketType: ... # timeout is undocumented
def makePickle(self, record: LogRecord) -> bytes: ...
@@ -112,6 +175,7 @@ class SysLogHandler(Handler):
unixsocket: bool # undocumented
socktype: SocketKind # undocumented
ident: str # undocumented
append_nul: bool # undocumented
facility: int # undocumented
priority_names: ClassVar[dict[str, int]] # undocumented
facility_names: ClassVar[dict[str, int]] # undocumented
@@ -130,31 +194,50 @@ class NTEventLogHandler(Handler):
def getMessageID(self, record: LogRecord) -> int: ...
class SMTPHandler(Handler):
# TODO `secure` can also be an empty tuple
mailhost: str # undocumented
mailport: Optional[int] # undocumented
username: Optional[str] # undocumented
# password only exists as an attribute if passed credentials is a tuple or list
password: str # undocumented
fromaddr: str # undocumented
toaddrs: list[str] # undocumented
subject: str # undocumented
secure: Union[tuple[()], tuple[str], tuple[str, str], None] # undocumented
timeout: float # undocumented
def __init__(
self,
mailhost: Union[str, tuple[str, int]],
fromaddr: str,
toaddrs: list[str],
toaddrs: Union[str, list[str]],
subject: str,
credentials: Optional[tuple[str, str]] = ...,
secure: Union[tuple[str], tuple[str, str], None] = ...,
secure: Union[tuple[()], tuple[str], tuple[str, str], None] = ...,
timeout: float = ...,
) -> None: ...
def getSubject(self, record: LogRecord) -> str: ...
class BufferingHandler(Handler):
buffer: list[LogRecord]
capacity: int # undocumented
buffer: list[LogRecord] # undocumented
def __init__(self, capacity: int) -> None: ...
def shouldFlush(self, record: LogRecord) -> bool: ...
class MemoryHandler(BufferingHandler):
flushLevel: int # undocumented
target: Optional[Handler] # undocumented
flushOnClose: bool # undocumented
def __init__(
self, capacity: int, flushLevel: int = ..., target: Optional[Handler] = ..., flushOnClose: bool = ...
) -> None: ...
def setTarget(self, target: Handler) -> None: ...
def setTarget(self, target: Optional[Handler]) -> None: ...
class HTTPHandler(Handler):
host: str # undocumented
url: str # undocumented
method: str # undocumented
secure: bool # undocumented
credentials: Optional[tuple[str, str]] # undocumented
context: Optional[ssl.SSLContext] # undocumented
def __init__(
self,
host: str,
@@ -165,24 +248,33 @@ class HTTPHandler(Handler):
context: Optional[ssl.SSLContext] = ...,
) -> None: ...
def mapLogRecord(self, record: LogRecord) -> dict[str, Any]: ...
if sys.version_info >= (3, 9):
def getConnection(self, host: str, secure: bool) -> http.client.HTTPConnection: ... # undocumented
class QueueHandler(Handler):
if sys.version_info >= (3, 7):
queue: Union[SimpleQueue[Any], Queue[Any]] # undocumented
def __init__(self, queue: Union[SimpleQueue[Any], Queue[Any]]) -> None: ...
else:
queue: Queue[Any] # undocumented
def __init__(self, queue: Queue[Any]) -> None: ...
def prepare(self, record: LogRecord) -> Any: ...
def enqueue(self, record: LogRecord) -> None: ...
class QueueListener:
handlers: tuple[Handler] # undocumented
respect_handler_level: bool # undocumented
if sys.version_info >= (3, 7):
queue: Union[SimpleQueue[Any], Queue[Any]] # undocumented
def __init__(
self, queue: Union[SimpleQueue[Any], Queue[Any]], *handlers: Handler, respect_handler_level: bool = ...
) -> None: ...
else:
queue: Queue[Any] # undocumented
def __init__(self, queue: Queue[Any], *handlers: Handler, respect_handler_level: bool = ...) -> None: ...
def dequeue(self, block: bool) -> LogRecord: ...
def prepare(self, record: LogRecord) -> Any: ...
def start(self) -> None: ...
def stop(self) -> None: ...
def enqueue_sentinel(self) -> None: ...
def handle(self, record: LogRecord) -> None: ...