Ligare.programming.patterns.dependency_injection

Injector dependency injection modules for extension by other modules.

Classes

BatchModule(registrations)

ConfigurableModule()

JSONFormatter([fmt_dict, time_format, ...])

Formatter that outputs JSON strings after parsing the LogRecord.

JSONLoggerModule([name, log_level, ...])

Force all loggers to use a StreamHandler that outputs JSON

LoggerModule([name, log_level, log_to_stdout])

class Ligare.programming.patterns.dependency_injection.BatchModule(registrations)[source]
__init__(registrations)[source]
configure(binder)[source]

Override to configure bindings.

Return type:

None

class Ligare.programming.patterns.dependency_injection.ConfigurableModule[source]
abstract static get_config_type()[source]
Return type:

type[AbstractConfig]

class Ligare.programming.patterns.dependency_injection.JSONFormatter(fmt_dict=None, time_format='%Y-%m-%dT%H:%M:%S', msec_format='%s.%03dZ')[source]

Formatter that outputs JSON strings after parsing the LogRecord. https://stackoverflow.com/a/70223539

@param dict fmt_dict: Key: logging format attribute pairs. Defaults to {“message”: “message”}. @param str time_format: time.strftime() format string. Default: “%Y-%m-%dT%H:%M:%S” @param str msec_format: Microsecond formatting. Appended at the end. Default: “%s.%03dZ”

__init__(fmt_dict=None, time_format='%Y-%m-%dT%H:%M:%S', msec_format='%s.%03dZ')[source]

Initialize the formatter with specified format strings.

Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.

Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, str.format() ({}) formatting or string.Template formatting in your format string.

Changed in version 3.2: Added the style parameter.

format(record)[source]

Mostly the same as the parent’s class method, the difference being that a dict is manipulated and dumped as JSON instead of a string.

Return type:

str

formatMessage(record)[source]

Overwritten to return a dictionary of the relevant LogRecord attributes instead of a string. KeyError is raised if an unknown attribute is provided in the fmt_dict.

Return type:

dict[str, Any]

usesTime()[source]

Overwritten to look for the attribute in the format dict values instead of the fmt string.

Return type:

bool

class Ligare.programming.patterns.dependency_injection.JSONLoggerModule(name=None, log_level=20, log_to_stdout=False, formatter=None)[source]

Force all loggers to use a StreamHandler that outputs JSON

__init__(name=None, log_level=20, log_to_stdout=False, formatter=None)[source]
configure(binder)[source]

Override to configure bindings.

Return type:

None

class Ligare.programming.patterns.dependency_injection.LoggerModule(name=None, log_level=20, log_to_stdout=False)[source]
__init__(name=None, log_level=20, log_to_stdout=False)[source]
configure(binder)[source]

Override to configure bindings.

Return type:

None