Source code for jgdv.logging._interface

  1#!/usr/bin/env python3
  2"""
  3
  4"""
  5# Imports:
  6from __future__ import annotations
  7
  8# ##-- stdlib imports
  9import datetime
 10import enum
 11import functools as ftz
 12import itertools as itz
 13import logging as logmod
 14import pathlib as pl
 15import re
 16import time
 17import types
 18import collections
 19import contextlib
 20import hashlib
 21from copy import deepcopy
 22from uuid import UUID, uuid1
 23from weakref import ref
 24import atexit # for @atexit.register
 25import faulthandler
 26# ##-- end stdlib imports
 27
 28# ##-- types
 29# isort: off
 30import abc
 31import collections.abc
 32from typing import TYPE_CHECKING, cast, assert_type, assert_never
 33from typing import Generic, NewType
 34# Protocols:
 35from typing import Protocol, runtime_checkable
 36# Typing Decorators:
 37from typing import no_type_check, final
 38
 39if TYPE_CHECKING:
 40    from jgdv import Maybe
 41    from jgdv.structs.chainguard import ChainGuard
 42    from typing import Final
 43    from typing import ClassVar, Any, LiteralString
 44    from typing import Never, Self, Literal
 45    from typing import TypeGuard
 46    from collections.abc import Iterable, Iterator, Callable, Generator
 47    from collections.abc import Sequence, Mapping, MutableMapping, Hashable
 48
 49##--|
 50
 51# isort: on
 52# ##-- end types
 53
 54##-- logging
 55logging = logmod.getLogger(__name__)
 56##-- end logging
 57
 58# Types
 59type Logger      = logmod.Logger
 60type Formatter   = logmod.Formatter
 61type Handler     = logmod.Handler
 62type LoggerSpec  = Any
 63
 64# Vars:
 65LOGDEC_PRE      : Final[str]       = "__logcall__"
 66PRINTER_NAME    : Final[str]       = "_printer_"
 67MAX_FILES       : Final[int]       = 5
 68TARGETS         : Final[list[str]] = [
 69    "file", "stdout", "stderr", "rotate", "pass",
 70]
 71
 72default_stdout  : Final[dict]      = {
 73    "name"           : logmod.root.name,
 74    "level"          : "user",
 75    "target"         : ["stdout"],
 76    "format"         : "{levelname}  : INIT : {message}",
 77    "style"          : "{",
 78    }
 79default_printer : Final[dict]      = {
 80    "name"           : PRINTER_NAME,
 81    "level"          : "user",
 82    "target"         : ["stdout"],
 83    "format"         : "{name}({levelname}) : {message}",
 84    "style"          : "{",
 85    "propagate"      : False,
 86    }
 87default_print_file : Final[str]    = "print.log"
 88
 89alt_log_colours : Final[dict[int, tuple[str, str]]] = {
 90    logmod.DEBUG    : ("fg", "grey"),
 91    logmod.INFO     : ("fg", "green"),
 92    logmod.WARNING  : ("fg", "blue"),
 93    logmod.ERROR    : ("fg", "red"),
 94    logmod.CRITICAL : ("fg", "red"),
 95}
 96
 97# Body:
 98
[docs] 99class LogLevel_e(enum.IntEnum): 100 """ My Preferred Loglevel names """ 101 error = logmod.ERROR # Total Failures 102 user = logmod.WARNING # User Notification 103 trace = logmod.INFO # Program Landmarks 104 detail = logmod.DEBUG # Exact values 105 bootstrap = logmod.NOTSET # Startup before configuration
106##--| 107
[docs] 108class LogConfig_p(Protocol): 109 """ The interface of how logging is configured. """ 110
[docs] 111 def setup(self, config:dict|ChainGuard) -> None: ...
112
[docs] 113 def set_level(self, level:int|str) -> None: ...
114
[docs] 115 def subprinter(self, *names:str) -> Logger: ...
116
[docs] 117 def activate_spec(self, spec:LoggerSpec, *, override:bool=False) -> None: ...
118
[docs] 119 def report(self) -> None: ...
120
[docs] 121 def reset(self) -> None: ...