Skip to main content

Audit

This class processes log files to track and analyze the lifecycle of tasks, including their reception, completion, and success status. It provides mechanisms to identify incomplete tasks and generate summary reports on task types and error counts. Users can also provide custom callback functions to handle task errors, trace information, and debug logs during the auditing process.

Attributes

AttributeTypeDescription
idsset = set()A set of unique task identifiers encountered during the audit process.
namesdict = {}A mapping of task identifiers to their corresponding task names.
resultsdict = {}A dictionary storing the result strings associated with each completed task identifier.
readyset = set()A set of task identifiers that have reached a ready state and completed execution.
task_typesCounter = Counter()A counter tracking the frequency of each task name encountered.
task_errorsint = 0The total count of tasks that failed to succeed during processing.
on_task_errorcallable = NoneAn optional callback function triggered when a task error is detected.
on_tracecallable = NoneAn optional callback function used to handle multi-line trace information when log lines do not match the start pattern.
on_debugcallable = NoneAn optional callback function invoked for log lines that match the start pattern but are not recognized as task events.
prev_linestring = NoneStores the content of the previous log line to facilitate multi-line trace reconstruction.

Constructor

Signature

def Audit(
on_task_error: callable = None,
on_trace: callable = None,
on_debug: callable = None
) - > null

Parameters

NameTypeDescription
on_task_errorcallable = NoneA callback function triggered when a task error is encountered.
on_tracecallable = NoneA callback function for handling trace-level log information.
on_debugcallable = NoneA callback function for handling debug-level log information.

Methods


run()

@classmethod
def run(
files: list
) - > [Audit](audit.md?sid=celery_bin_logtool_audit)

Processes a collection of log files to audit task execution by feeding each line into the parser.

Parameters

NameTypeDescription
fileslistA list of file paths or file-like objects to be read and audited.

Returns

TypeDescription
[Audit](audit.md?sid=celery_bin_logtool_audit)The current Audit instance after processing all input files.

task_received()

@classmethod
def task_received(
line: string,
task_name: string,
task_id: string
)

Registers a new task entry, tracking its unique identifier and incrementing the count for its specific task type.

Parameters

NameTypeDescription
linestringThe raw log line containing the task reception event.
task_namestringThe descriptive name or category of the task being received.
task_idstringThe unique UUID or identifier associated with the specific task instance.

task_ready()

@classmethod
def task_ready(
line: string,
task_name: string,
task_id: string,
result: string
)

Marks a task as completed and stores its result, triggering an error handler if the task did not succeed.

Parameters

NameTypeDescription
linestringThe raw log line indicating the task has finished processing.
task_namestringThe name of the task that has reached the ready state.
task_idstringThe unique identifier of the completed task.
resultstringThe outcome message or status string returned by the task execution.

task_error()

@classmethod
def task_error(
line: string,
task_name: string,
task_id: string,
result: string
)

Increments the global error counter and executes the optional error callback for a failed task.

Parameters

NameTypeDescription
linestringThe log line associated with the task failure.
task_namestringThe name of the task that encountered an error.
task_idstringThe unique identifier of the failed task.
resultstringThe error details or failure status returned by the task.

feed()

@classmethod
def feed(
line: string
)

Parses a single log line to identify task lifecycle events or trigger trace and debug callbacks for unrecognized lines.

Parameters

NameTypeDescription
linestringA single line of text from the log file to be analyzed.

incomplete_tasks()

@classmethod
def incomplete_tasks() - > set

Identifies tasks that were received but never reached a ready state.

Returns

TypeDescription
setA set of task IDs representing tasks that are still pending or lost.

report()

@classmethod
def report() - > dict

Generates a summary dictionary containing statistics on task types, totals, completions, and success rates.

Returns

TypeDescription
dictA nested dictionary containing aggregated audit metrics for all processed tasks.