pain001.context package#

Application context package for pain001.

Submodules#

pain001.context.context module#

Singleton application context that owns the shared pain001 logger.

class pain001.context.context.Context[source]#

Bases: object

A singleton that manages the shared pain001 logger.

Instantiating the class directly raises RuntimeError once the singleton exists; use get_instance() instead.

Lifecycle overview (method details are documented below):

  • __init__ initializes the class and creates a logger.

  • get_instance returns the singleton instance.

  • get_logger returns the logger.

  • init_logger initializes the logger.

  • set_log_level sets the logger’s level.

  • set_name sets the logger’s name.

static get_instance() → Context[source]#

Returns the singleton instance of the class.

Returns:

A Context instance.

Raises:

RuntimeError – If the singleton failed to initialize (defensive check; unreachable in practice).

get_logger() → Logger[source]#

Returns the logger.

Returns:

A Logger instance.

init_logger() → None[source]#

Initializes the logger.

Raises:

RuntimeError – If the logger has already been initialized.

instance: Context | None = None#
set_log_level(log_level: int) → None[source]#

Sets the log level of the logger.

Parameters:

log_level – The log level of the logger.

Raises:

ValueError – If the log level is invalid.

set_name(name: str) → None[source]#

Sets the name of the logger.

Parameters:

name – The name of the logger. Empty names are coerced to “pain001” so the root logger is never claimed.