Smarter Logging Utilities
Logging utilities for the Smarter app.
WaffleSwitchedLoggerWrapper uses these to start
every log message with the dotted name of the function or method that logged it, so that call sites
never write their own name into a message.
- smarter.lib.logging.utils.SELF_PARAMETER_NAMES = ('self', 'cls')
The names of a method’s first parameter that
runtime_class()trusts to be its instance or class.('self', 'cls')
- smarter.lib.logging.utils.caller_name(frame)[source]
Return the dotted name of the function or method that a frame is running, for logging.
- Parameters:
frame (
FrameType) – A frame of the call stack, e.g. the caller of a logging method.- Return type:
- Returns:
The module and qualified name followed by parentheses, e.g.
smarter.apps.llmtool.models.plugin_data_api.PluginDataApi.execute_request(). A method is named after the class that runs it (seeruntime_class()); code at module level is named by its module alone.
- smarter.lib.logging.utils.formatted_caller_name(frame, prefix_format=None)[source]
Return the name of a frame’s function or method in the log prefix’s color.
- Parameters:
- Return type:
- Returns:
caller_name(), formatted withSmarterFormattedText.text().
- smarter.lib.logging.utils.prefixed_message(prefix, msg, has_args)[source]
Return a log message that starts with a prefix.
The prefix is written into the message, rather than passed as an argument, so that the message’s own arguments, including a single mapping for
%(name)splaceholders, are left as they are.- Parameters:
- Return type:
- Returns:
The prefix, a space, then the message.
- smarter.lib.logging.utils.runtime_class(frame)[source]
Return the class that runs the method of a frame, or None if the frame isn’t a method’s.
A method inherited from a base class or a mixin is run by the instance’s own class, so a log entry can say which subclass ran it. The frame’s first parameter must be
selforcls, and the class that defines the code must be in its class’s MRO, so that a function whose first parameter only happens to be calledself(e.g. a bound Celery task) keeps its own name.