yggdrasil.pickle.ser.logging¶
logging ¶
logging.py – Serializers for Python :mod:logging objects.
Wire tags (all in the system range 200–299):
LOGGING_LOGGER (216) – :class:`logging.Logger` / :class:`logging.RootLogger`
LOGGING_HANDLER (217) – :class:`logging.Handler` and concrete subclasses
LOGGING_FORMATTER (218) – :class:`logging.Formatter`
LOGGING_LOG_RECORD (219) – :class:`logging.LogRecord`
Design notes¶
- Loggers are reference-serialised by name: they are singletons managed by
:func:
logging.getLogger, so we only store the name + effective level and re-bind on load. - Handlers are reconstructed from their class reference plus the subset of
state that is safe and portable (level, formatter, filters by name).
Handler-specific init args (filename, stream, host/port, …) are stored via
__getstate__when available; otherwise we fall back to a dict extracted from__dict__. - Formatters store their format strings (fmt, datefmt, style, defaults).
- LogRecords store all their public fields as a plain tuple payload.
The payload format uses :func:yggdrasil.pickle.ser.serialized.Serialized
round-tripped msgpack-like nested bytes so that each sub-object goes through
the normal serializer stack.
LoggingSerialized
dataclass
¶
Bases: Serialized[object]
Abstract base for all logging-related serializers.
Concrete subclasses override :meth:as_python and :meth:from_python_object.
module_and_name
staticmethod
¶
Return (module, qualname) for obj.
Robust across Python objects, including many C-extension / PyArrow objects where module may be missing or misleading.
LoggerSerialized
dataclass
¶
Bases: LoggingSerialized
Serializer for :class:logging.Logger.
Loggers are singletons: we persist the name and effective level only.
On deserialisation we call :func:logging.getLogger to obtain the
canonical instance, and (optionally) set the level when the logger has not
been explicitly configured yet.
module_and_name
staticmethod
¶
Return (module, qualname) for obj.
Robust across Python objects, including many C-extension / PyArrow objects where module may be missing or misleading.
HandlerSerialized
dataclass
¶
Bases: LoggingSerialized
Serializer for :class:logging.Handler and its subclasses.
Only portable state is captured:
- Handler class (module + qualname)
- Level
- Formatter (if set)
- Filter names
- Handler-specific extra state (
__getstate__or__dict__subset)
The handler is reconstructed via :func:_handler_try_reconstruct; if
reconstruction fails, a plain :class:logging.NullHandler is returned
instead.
module_and_name
staticmethod
¶
Return (module, qualname) for obj.
Robust across Python objects, including many C-extension / PyArrow objects where module may be missing or misleading.
FormatterSerialized
dataclass
¶
Bases: LoggingSerialized
Serializer for :class:logging.Formatter.
Stores format string, date format, style, validation flag, and any extra
defaults mapping. Custom :class:logging.Formatter subclasses that
do not require special construction args will round-trip faithfully; more
exotic subclasses are reconstructed as plain :class:logging.Formatter.
module_and_name
staticmethod
¶
Return (module, qualname) for obj.
Robust across Python objects, including many C-extension / PyArrow objects where module may be missing or misleading.
LogRecordSerialized
dataclass
¶
Bases: LoggingSerialized
Serializer for :class:logging.LogRecord.
All public fields are persisted. Exception info (exc_info) is
serialised as a pickled bytes blob when the exception object is available;
otherwise it is dropped.
module_and_name
staticmethod
¶
Return (module, qualname) for obj.
Robust across Python objects, including many C-extension / PyArrow objects where module may be missing or misleading.