omlish 0.0.0.dev431__py3-none-any.whl → 0.0.0.dev432__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omlish/__about__.py +2 -2
- omlish/logs/all.py +8 -0
- omlish/logs/contexts.py +10 -0
- omlish/logs/formatters.py +13 -0
- omlish/logs/standard.py +10 -6
- omlish/logs/std/formatters.py +25 -0
- omlish/logs/std/records.py +56 -14
- {omlish-0.0.0.dev431.dist-info → omlish-0.0.0.dev432.dist-info}/METADATA +1 -1
- {omlish-0.0.0.dev431.dist-info → omlish-0.0.0.dev432.dist-info}/RECORD +13 -11
- {omlish-0.0.0.dev431.dist-info → omlish-0.0.0.dev432.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev431.dist-info → omlish-0.0.0.dev432.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev431.dist-info → omlish-0.0.0.dev432.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev431.dist-info → omlish-0.0.0.dev432.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
omlish/logs/all.py
CHANGED
@@ -9,6 +9,10 @@ with _lang.auto_proxy_init(globals()):
|
|
9
9
|
TidLoggingFilter,
|
10
10
|
)
|
11
11
|
|
12
|
+
from .std.formatters import ( # noqa
|
13
|
+
StdLoggingFormatter,
|
14
|
+
)
|
15
|
+
|
12
16
|
from .std.handlers import ( # noqa
|
13
17
|
ListLoggingHandler,
|
14
18
|
)
|
@@ -48,6 +52,10 @@ with _lang.auto_proxy_init(globals()):
|
|
48
52
|
LoggingContext,
|
49
53
|
)
|
50
54
|
|
55
|
+
from .formatters import ( # noqa
|
56
|
+
LoggingContextFormatter,
|
57
|
+
)
|
58
|
+
|
51
59
|
from .infos import ( # noqa
|
52
60
|
LoggingContextInfo,
|
53
61
|
LoggingContextInfos,
|
omlish/logs/contexts.py
CHANGED
@@ -33,6 +33,16 @@ class LoggingContext(Abstract):
|
|
33
33
|
raise TypeError(f'LoggingContextInfo absent: {ty}')
|
34
34
|
return info
|
35
35
|
|
36
|
+
|
37
|
+
@ta.final
|
38
|
+
class SimpleLoggingContext(LoggingContext):
|
39
|
+
def __init__(self, *infos: LoggingContextInfo) -> None:
|
40
|
+
self._infos: ta.Dict[ta.Type[LoggingContextInfo], LoggingContextInfo] = {type(i): i for i in infos}
|
41
|
+
|
42
|
+
def get_info(self, ty: ta.Type[LoggingContextInfoT]) -> ta.Optional[LoggingContextInfoT]:
|
43
|
+
return self._infos.get(ty)
|
44
|
+
|
45
|
+
|
36
46
|
##
|
37
47
|
|
38
48
|
|
omlish/logs/standard.py
CHANGED
@@ -80,10 +80,14 @@ def _locking_logging_module_lock() -> ta.Iterator[None]:
|
|
80
80
|
def configure_standard_logging(
|
81
81
|
level: ta.Union[int, str] = logging.INFO,
|
82
82
|
*,
|
83
|
-
json: bool = False,
|
84
83
|
target: ta.Optional[logging.Logger] = None,
|
84
|
+
|
85
85
|
force: bool = False,
|
86
|
+
|
86
87
|
handler_factory: ta.Optional[ta.Callable[[], logging.Handler]] = None,
|
88
|
+
|
89
|
+
formatter: ta.Optional[logging.Formatter] = None, # noqa
|
90
|
+
json: bool = False,
|
87
91
|
) -> ta.Optional[StandardConfiguredLoggingHandler]:
|
88
92
|
with _locking_logging_module_lock():
|
89
93
|
if target is None:
|
@@ -104,11 +108,11 @@ def configure_standard_logging(
|
|
104
108
|
|
105
109
|
#
|
106
110
|
|
107
|
-
formatter:
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
111
|
+
if formatter is None:
|
112
|
+
if json:
|
113
|
+
formatter = JsonLoggingFormatter()
|
114
|
+
else:
|
115
|
+
formatter = StandardLoggingFormatter(StandardLoggingFormatter.build_log_format(STANDARD_LOG_FORMAT_PARTS)) # noqa
|
112
116
|
handler.setFormatter(formatter)
|
113
117
|
|
114
118
|
#
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import logging
|
2
|
+
import typing as ta
|
3
|
+
|
4
|
+
from ..formatters import LoggingContextFormatter
|
5
|
+
from .records import LoggingContextLogRecord
|
6
|
+
from .records import LogRecordLoggingContext
|
7
|
+
|
8
|
+
|
9
|
+
##
|
10
|
+
|
11
|
+
|
12
|
+
@ta.final
|
13
|
+
class StdLoggingFormatter(logging.Formatter):
|
14
|
+
def __init__(self, ctx_formatter: LoggingContextFormatter) -> None:
|
15
|
+
super().__init__()
|
16
|
+
|
17
|
+
self._ctx_formatter = ctx_formatter
|
18
|
+
|
19
|
+
def format(self, rec: logging.LogRecord) -> str:
|
20
|
+
if isinstance(rec, LoggingContextLogRecord):
|
21
|
+
ctx = rec._logging_context # noqa
|
22
|
+
else:
|
23
|
+
ctx = LogRecordLoggingContext(rec)
|
24
|
+
|
25
|
+
return self._ctx_formatter.format(ctx)
|
omlish/logs/std/records.py
CHANGED
@@ -11,6 +11,7 @@ import typing as ta
|
|
11
11
|
|
12
12
|
from ...lite.abstract import Abstract
|
13
13
|
from ..contexts import LoggingContext
|
14
|
+
from ..contexts import LoggingContextInfoT
|
14
15
|
from ..infos import LoggingContextInfo
|
15
16
|
from ..infos import LoggingContextInfos
|
16
17
|
from ..infos import LoggingExcInfoTuple
|
@@ -356,8 +357,23 @@ class LoggingContextInfoRecordAdapters:
|
|
356
357
|
|
357
358
|
def record_to_info(self, rec: logging.LogRecord) -> ta.Optional[LoggingContextInfos.Caller]:
|
358
359
|
# FIXME: piecemeal?
|
359
|
-
|
360
|
-
|
360
|
+
if (
|
361
|
+
rec.pathname != self._UNKNOWN_PATH_NAME and
|
362
|
+
rec.lineno != 0 and
|
363
|
+
rec.funcName != self._UNKNOWN_FUNC_NAME
|
364
|
+
):
|
365
|
+
if (sinfo := rec.stack_info) is not None and sinfo.startswith(self._STACK_INFO_PREFIX):
|
366
|
+
sinfo = sinfo[len(self._STACK_INFO_PREFIX):]
|
367
|
+
return LoggingContextInfos.Caller(
|
368
|
+
file_path=rec.pathname,
|
369
|
+
|
370
|
+
line_no=rec.lineno,
|
371
|
+
func_name=rec.funcName,
|
372
|
+
|
373
|
+
stack_info=sinfo,
|
374
|
+
)
|
375
|
+
|
376
|
+
return None
|
361
377
|
|
362
378
|
class SourceFile(Adapter[LoggingContextInfos.SourceFile]):
|
363
379
|
info_cls: ta.ClassVar[ta.Type[LoggingContextInfos.SourceFile]] = LoggingContextInfos.SourceFile
|
@@ -393,9 +409,9 @@ class LoggingContextInfoRecordAdapters:
|
|
393
409
|
)
|
394
410
|
|
395
411
|
def record_to_info(self, rec: logging.LogRecord) -> ta.Optional[LoggingContextInfos.SourceFile]:
|
396
|
-
if
|
397
|
-
rec.module is None
|
398
|
-
rec.module
|
412
|
+
if (
|
413
|
+
rec.module is not None and
|
414
|
+
rec.module != self._UNKNOWN_MODULE
|
399
415
|
):
|
400
416
|
return LoggingContextInfos.SourceFile(
|
401
417
|
file_name=rec.filename,
|
@@ -548,16 +564,11 @@ _LOGGING_CONTEXT_INFO_RECORD_ADAPTERS: ta.Mapping[ta.Type[LoggingContextInfo], L
|
|
548
564
|
##
|
549
565
|
|
550
566
|
|
551
|
-
KNOWN_STD_LOGGING_RECORD_ATTR_SET: ta.FrozenSet[str] = frozenset(
|
552
|
-
a for ad in _LOGGING_CONTEXT_INFO_RECORD_ADAPTERS.values() for a in ad.record_attrs
|
553
|
-
)
|
554
|
-
|
555
|
-
|
556
567
|
# Formatter:
|
557
568
|
# - https://github.com/python/cpython/blob/39b2f82717a69dde7212bc39b673b0f55c99e6a3/Lib/logging/__init__.py#L514 (3.8)
|
558
569
|
# - https://github.com/python/cpython/blob/f070f54c5f4a42c7c61d1d5d3b8f3b7203b4a0fb/Lib/logging/__init__.py#L554 (~3.14) # noqa
|
559
570
|
#
|
560
|
-
|
571
|
+
_KNOWN_STD_LOGGING_FORMATTER_RECORD_ATTRS: ta.Dict[str, ta.Any] = dict(
|
561
572
|
# The logged message, computed as msg % args. Set to `record.getMessage()`.
|
562
573
|
message=str,
|
563
574
|
|
@@ -571,7 +582,15 @@ KNOWN_STD_LOGGING_FORMATTER_RECORD_ATTRS: ta.Dict[str, ta.Any] = dict(
|
|
571
582
|
exc_text=ta.Optional[str],
|
572
583
|
)
|
573
584
|
|
574
|
-
|
585
|
+
|
586
|
+
##
|
587
|
+
|
588
|
+
|
589
|
+
_KNOWN_STD_LOGGING_RECORD_ATTR_SET: ta.FrozenSet[str] = frozenset(
|
590
|
+
a for ad in _LOGGING_CONTEXT_INFO_RECORD_ADAPTERS.values() for a in ad.record_attrs
|
591
|
+
)
|
592
|
+
|
593
|
+
_KNOWN_STD_LOGGING_FORMATTER_RECORD_ATTR_SET: ta.FrozenSet[str] = frozenset(_KNOWN_STD_LOGGING_FORMATTER_RECORD_ATTRS)
|
575
594
|
|
576
595
|
|
577
596
|
class UnknownStdLoggingRecordAttrsWarning(LoggingSetupWarning):
|
@@ -581,13 +600,13 @@ class UnknownStdLoggingRecordAttrsWarning(LoggingSetupWarning):
|
|
581
600
|
def _check_std_logging_record_attrs() -> None:
|
582
601
|
if (
|
583
602
|
len([a for ad in _LOGGING_CONTEXT_INFO_RECORD_ADAPTERS.values() for a in ad.record_attrs]) !=
|
584
|
-
len(
|
603
|
+
len(_KNOWN_STD_LOGGING_RECORD_ATTR_SET)
|
585
604
|
):
|
586
605
|
raise RuntimeError('Duplicate LoggingContextInfoRecordAdapter record attrs')
|
587
606
|
|
588
607
|
rec_dct = dict(logging.makeLogRecord({}).__dict__)
|
589
608
|
|
590
|
-
if (unk_rec_fields := frozenset(rec_dct) -
|
609
|
+
if (unk_rec_fields := frozenset(rec_dct) - _KNOWN_STD_LOGGING_RECORD_ATTR_SET):
|
591
610
|
import warnings # noqa
|
592
611
|
|
593
612
|
warnings.warn(
|
@@ -615,5 +634,28 @@ class LoggingContextLogRecord(logging.LogRecord):
|
|
615
634
|
# - sinfo: str | None = None -> stack_info
|
616
635
|
|
617
636
|
def __init__(self, *, _logging_context: LoggingContext) -> None: # noqa
|
637
|
+
self._logging_context = _logging_context
|
638
|
+
|
618
639
|
for ad in _LOGGING_CONTEXT_INFO_RECORD_ADAPTERS_:
|
619
640
|
self.__dict__.update(ad.context_to_record(_logging_context))
|
641
|
+
|
642
|
+
|
643
|
+
##
|
644
|
+
|
645
|
+
|
646
|
+
@ta.final
|
647
|
+
class LogRecordLoggingContext(LoggingContext):
|
648
|
+
def __init__(self, rec: logging.LogRecord) -> None:
|
649
|
+
if isinstance(rec, LoggingContextLogRecord):
|
650
|
+
raise TypeError(rec)
|
651
|
+
|
652
|
+
self._rec = rec
|
653
|
+
|
654
|
+
self._infos: ta.Dict[ta.Type[LoggingContextInfo], LoggingContextInfo] = {
|
655
|
+
type(info): info
|
656
|
+
for ad in _LOGGING_CONTEXT_INFO_RECORD_ADAPTERS_
|
657
|
+
if (info := ad.record_to_info(rec)) is not None
|
658
|
+
}
|
659
|
+
|
660
|
+
def get_info(self, ty: ta.Type[LoggingContextInfoT]) -> ta.Optional[LoggingContextInfoT]:
|
661
|
+
return self._infos.get(ty)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
omlish/.omlish-manifests.json,sha256=FLw7xkPiSXuImZgqSP8BwrEib2R1doSzUPLUkc-QUIA,8410
|
2
|
-
omlish/__about__.py,sha256=
|
2
|
+
omlish/__about__.py,sha256=3-_QYxv_HRPE-514v1MBZ6PctnESC50f34-uw3VRp7U,3575
|
3
3
|
omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
|
4
4
|
omlish/c3.py,sha256=ZNIMl1kwg3qdei4DiUrJPQe5M81S1e76N-GuNSwLBAE,8683
|
5
5
|
omlish/cached.py,sha256=MLap_p0rdGoDIMVhXVHm1tsbcWobJF0OanoodV03Ju8,542
|
@@ -497,25 +497,27 @@ omlish/lite/types.py,sha256=QM9whf55r7TmmQBRApIWSlyVKsl1p_jcut_YheyZMFY,146
|
|
497
497
|
omlish/lite/typing.py,sha256=m2CyJTz2OVOCPRvp-0UuEx7oleZgXqs3rYXijE0bTsA,1280
|
498
498
|
omlish/lite/wrappers.py,sha256=d00Ls2kFHuogKd5wEBaU65VNCN10YXIZtiwu1mbMpmA,530
|
499
499
|
omlish/logs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
500
|
-
omlish/logs/all.py,sha256=
|
500
|
+
omlish/logs/all.py,sha256=GqST35bRnHgpGmQXvtHih7kLaw5DcFgB32uxPGAsgSI,1717
|
501
501
|
omlish/logs/base.py,sha256=Z1hfwYS2LgMJxFIyHiOvYa2meu2MH3kQDkhaWRNzt0M,5698
|
502
|
-
omlish/logs/contexts.py,sha256=
|
502
|
+
omlish/logs/contexts.py,sha256=bTja5uA2V2VMoPnPrBxRfzUDgD0giRA0RVbtwrp3Xv4,4797
|
503
|
+
omlish/logs/formatters.py,sha256=g8oGfP_ok0nrW9opIIh5LqcQTmdufWFGO-9pRKX4m3Q,242
|
503
504
|
omlish/logs/infos.py,sha256=Nr2SbyI978vP5BTiVZsXUBdy2k0CUiwggcW-wewJHmo,11560
|
504
505
|
omlish/logs/levels.py,sha256=Eze-k_LPgFzbNMnG10F2bRKfL3veQpIxiegvN5rGeWM,2909
|
505
506
|
omlish/logs/modules.py,sha256=wZ_PNCYhAaEdnGE5k0JvChcqn9nhtEpmwuH74Bwn5gg,266
|
506
507
|
omlish/logs/protocols.py,sha256=e_zizD3pQdYlU6bg3xGB3_ARUTcoHUfar_uLjCo-SPw,961
|
507
|
-
omlish/logs/standard.py,sha256=
|
508
|
+
omlish/logs/standard.py,sha256=btp0YOUb3AsANG0D1rqGK-z25O4HN7p1PJj9ecJ80WI,3323
|
508
509
|
omlish/logs/utils.py,sha256=fKvP342qBmE8wwTgUQ8Tf0-ATVhCm90UYBQt2pk0044,1883
|
509
510
|
omlish/logs/warnings.py,sha256=xyhDgiPy1p8Kp5D9sb_NZiBnQ26SUppaHqC27dtQzok,67
|
510
511
|
omlish/logs/std/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
511
512
|
omlish/logs/std/configs.py,sha256=aDQahqBJXJpmQBaxXVK5S2xi_I_nrLLcCLTq6Q2K6EQ,1037
|
512
513
|
omlish/logs/std/filters.py,sha256=Z8tHOvBRiP-OYm2z5cwY-lYXRimNgferEARMwvwx5Pw,380
|
514
|
+
omlish/logs/std/formatters.py,sha256=mORjx6kPQ-nYvek0Lyg1PZh0vtSYr6Vk-UJtRNW9_8k,645
|
513
515
|
omlish/logs/std/handlers.py,sha256=uTWOT6oayBUEftKmJ8yo89ZP4plv5eQ8Lbcmt-IGl8c,469
|
514
516
|
omlish/logs/std/json.py,sha256=QJ5lywLsRsPyVno2nk2kOw-Z1z3bfrDiZzqcRUdWUMY,1382
|
515
517
|
omlish/logs/std/loggers.py,sha256=hJIEC5BGaDOxgikTYKJ_qA_moS4CcHLMDAVKFDDKdHo,1144
|
516
518
|
omlish/logs/std/noisy.py,sha256=hWpbseerZqlHdEPEajDTSmcRhx8LmmNAxz_7GBZAO9s,353
|
517
519
|
omlish/logs/std/proxy.py,sha256=9MVV5kbj9nwl3KZGtrYCIb5XTpv33f33zZ7P_B58fX0,2394
|
518
|
-
omlish/logs/std/records.py,sha256=
|
520
|
+
omlish/logs/std/records.py,sha256=NbprlkTQV8Y89nP2c27m3nE0OY3SWmQHCl-o_rQfs50,25476
|
519
521
|
omlish/logs/typed/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
520
522
|
omlish/logs/typed/bindings.py,sha256=H_B-3LTGFlBIWYDJ8rei1VMfInE8KrBwRo3bJ_BgFj8,18184
|
521
523
|
omlish/logs/typed/contexts.py,sha256=MU1RqHtmYbnxoLfLhMZbTbRd-WfYEyeVo7_3VnG3rY0,4027
|
@@ -890,9 +892,9 @@ omlish/typedvalues/marshal.py,sha256=AtBz7Jq-BfW8vwM7HSxSpR85JAXmxK2T0xDblmm1HI0
|
|
890
892
|
omlish/typedvalues/of_.py,sha256=UXkxSj504WI2UrFlqdZJbu2hyDwBhL7XVrc2qdR02GQ,1309
|
891
893
|
omlish/typedvalues/reflect.py,sha256=PAvKW6T4cW7u--iX80w3HWwZUS3SmIZ2_lQjT65uAyk,1026
|
892
894
|
omlish/typedvalues/values.py,sha256=ym46I-q2QJ_6l4UlERqv3yj87R-kp8nCKMRph0xQ3UA,1307
|
893
|
-
omlish-0.0.0.
|
894
|
-
omlish-0.0.0.
|
895
|
-
omlish-0.0.0.
|
896
|
-
omlish-0.0.0.
|
897
|
-
omlish-0.0.0.
|
898
|
-
omlish-0.0.0.
|
895
|
+
omlish-0.0.0.dev432.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
896
|
+
omlish-0.0.0.dev432.dist-info/METADATA,sha256=bfGoM5Z4MjOp8DULPuEbClTLTNoyTilZ3sKRe-c5SRk,19243
|
897
|
+
omlish-0.0.0.dev432.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
898
|
+
omlish-0.0.0.dev432.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
|
899
|
+
omlish-0.0.0.dev432.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
|
900
|
+
omlish-0.0.0.dev432.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|