On this page

Attach logging explicitly๏ƒ

Prerequisite: configuration ownership. Melder's root starts without an attached raw logger. Use md.Aether().attach_logger(logger) to install one after boot; passing None detaches it again.

The saved logging lesson uses a standard-library logger with a collecting handler. It checks the public aether.logger after attachment, detachment, and enable_logging(logger), then removes and closes the demonstration's handler.

Two enablement paths๏ƒ

An explicit logger passed to enable_logging uses the attachment path. Calling enable_logging() without one instead requires the automatic logger policy and provider setup. Do not assume creating an AetherConfiguration enabled that path; follow the root-configuration lesson's activation sequence.

Own the lifetime of application logging resources explicitly. Root logger attachment and provider configuration are separate choices; installing one sink does not by itself describe the policy of every object already in the process.

The workflow in code๏ƒ

These are the core steps from the saved example. Use its complete linked script for all class definitions and setup.

 1def main() -> None:
 2    """Verify public attach, detach, and explicit enable behavior; release the handler."""
 3    aether = md.Aether()
 4
 5    # Build a real stdlib logger with a capturing handler...
 6    handler = CollectingHandler()
 7    logger = logging.getLogger("melder-advanced-05")
 8    logger.setLevel(logging.DEBUG)
 9    logger.addHandler(handler)
10
11    # ...and attach it through the public post-boot seam.
12    aether.attach_logger(logger)
13    assert aether.logger is logger
14    print("logger attached; the world is no longer silent")
15
16    # Detaching is the same door with None - back to the null wrapper.
17    aether.attach_logger(None)
18    assert aether.logger is None
19    print("detached; melder is silent again (the boot default)")
20
21    # enable_logging(explicit) is attach; enable_logging() with no
22    # argument asks the configured channel policy instead.
23    aether.enable_logging(logger)
24    assert aether.logger is logger
25    print("enable_logging(explicit) attached the same logger")
26    aether.attach_logger(None)
27    assert aether.logger is None
28    logger.removeHandler(handler)
29    handler.close()

Runnable examples๏ƒ

All advanced examples ยท Level contents ยท Full contents

Canonical page source