quri_parts.core.utils.recording module#
- class RecordLevel(value)#
Bases:
IntEnum
Level of recording, which specifies importance of a recording event.
A larger value means higher importance. Record level is a concept similar to
logging
level. Currently each record level has its counterpartlogging
level with the same integer value.- INFO = 20#
- DEBUG = 10#
- INFO = RecordLevel.INFO#
INFO level
- DEBUG = RecordLevel.DEBUG#
DEBUG level
- class RecordableFunctionId(module, qualname, param)#
Bases:
NamedTuple
Represents an identifier for a recordable function.
- Parameters:
module (str) –
qualname (str) –
param (Hashable) –
- module: str#
Name of the module which the function belongs to.
- qualname: str#
Qualified name of the function.
- param: Hashable#
Other parameters necessary for identifying a function. It is currently unused.
- to_str(full=True)#
Returns a string representation of itself.
If
full
is True, the returned string contains the module name.- Parameters:
full (bool) –
- Return type:
str
- class RecordableFunction(*args, **kwargs)#
Bases:
Protocol
[P
,R
]Represents an instance of a recordable function with its identifier, which can be accessed via
id
attribute.
- recordable(f)#
A decorator for creating a recordable function.
A function to which this decorator is applied must receive a
Recorder
as its first positional argument, which can be used for recording in the function body. This decorator removes theRecorder
argument, so a user of the recordable function does not need to pass aRecorder
instance. This decorator also adds aRecordableFunctionId
, which can be accesed viaid
attribute.Note that when you store mutable data such as list, RecordEntry does not store the snapshot of the data. This means that the data you get is the latest one when you access it. If you want to get the snapshot of the data, you need to copy it by yourself.
- Parameters:
f (Callable[[Recorder, P], R]) –
- Return type:
RecordableFunction[P, R]
- class Recorder(fid)#
Bases:
object
Data recorder given to the function which uses data to record.
For the function generated by
recordable()
, each function call starts with callingstart_func()
, which creates a newRecordGroup
for the function. Note that you should first createRecordSession
to record the data.- Parameters:
fid (RecordableFunctionId) –
- start_func()#
Context manager to be called for each
RecordableFunction
call.- Return type:
Iterator[None]
- record(level, key, value)#
Records the given data to
RecordGroup
s which belong to activeRecordSession
s.- Parameters:
level (RecordLevel) –
key (core.utils.recording._RecKey) –
value (core.utils.recording._RecValue) –
- Return type:
None
- debug(key, value)#
Records the given data with DEBUG level.
- Parameters:
key (core.utils.recording._RecKey) –
value (core.utils.recording._RecValue) –
- Return type:
None
- info(key, value)#
Records the given data with INFO level.
- Parameters:
key (core.utils.recording._RecKey) –
value (core.utils.recording._RecValue) –
- Return type:
None
- is_enabled_for(level)#
Checks if there is any active
RecordSession
which records the data with level or lower.- Parameters:
level (RecordLevel) –
- Return type:
bool
- class RecordEntry(level, func_id, data)#
Bases:
object
Represents a record data entry with its
RecordLevel
andRecordableFunctionId
.- Parameters:
level (RecordLevel) –
func_id (RecordableFunctionId) –
data (core.utils.recording._RecData) –
- level: RecordLevel#
- func_id: RecordableFunctionId#
- data: _RecData#
- class RecordGroup(func_id, entries, id=<factory>)#
Bases:
object
Represents a group of data, which contains the list of
RecordEntry
s withRecordableFunctionId
. This group is created for everyRecordableFunction
calls.- Parameters:
func_id (RecordableFunctionId) –
entries (list[RecordEntry]) –
id (int) –
- func_id: RecordableFunctionId#
- entries: list[RecordEntry]#
- id: int#
- add_entry(entry)#
Adds entry to the group.
- Parameters:
entry (RecordEntry) –
- Return type:
None
- class RecordSet#
Bases:
object
Set of
RecordGroup
stored in sequence.- add_group(fid)#
Creates and adds a
RecordGroup
for givenRecordableFunctionId
.- Parameters:
fid (RecordableFunctionId) –
- Return type:
- remove_last_group()#
Remove the last group from the sequence of
RecordGroup
s.- Return type:
None
- get_history(func)#
Returns the
RecordGroup
s corresponding to theRecordableFunction
as an Iterable.- Parameters:
func (RecordableFunction[P, R]) –
- Return type:
Iterable[RecordGroup]
- class RecordSession#
Bases:
object
A session manages data recording from recordable functions.
It internally stores recording data received from recordable functions. It also calls associated loggers when receiving data recording events.
- set_level(level, func)#
Set a record level for the specified recordable function in this session.
- Parameters:
level (RecordLevel) –
func (RecordableFunction[P, R]) –
- Return type:
None
- is_enabled_for(level, fid)#
Checks if recording of the given level is enabled for the specified recordable function in this session.
Returns true if the record level set for the function is equal to or smaller than given level.
- Parameters:
level (RecordLevel) –
fid (RecordableFunctionId) –
- Return type:
bool
- handler(level, fid, key, value)#
Handles a data recording event.
Internally, a
RecordEntry
for the event is created and loggers associated with the session are invoked.- Parameters:
level (RecordLevel) –
fid (RecordableFunctionId) –
key (core.utils.recording._RecKey) –
value (core.utils.recording._RecValue) –
- Return type:
None
- start()#
Starts the data recording session.
- Return type:
Iterator[None]
- add_logger(logger=None)#
Connect a logger which logs data recording events received by the session.
- Parameters:
logger (Logger | None) –
- Return type:
None