51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
from .application_logger import ApplicationLogger
|
|
|
|
|
|
class FunctionLogger(ApplicationLogger):
|
|
def __init__(self, sender_id: str, receiver_id:str) -> None:
|
|
super().__init__()
|
|
self.event_sender_id = sender_id
|
|
self.event_receiver_id = receiver_id
|
|
self.event_subject = "function"
|
|
|
|
async def log_enter(self, function: str, file: str):
|
|
return await super().log_event(
|
|
sender_id=self.event_sender_id,
|
|
receiver_id=self.event_receiver_id,
|
|
subject=self.event_subject,
|
|
event="enter",
|
|
properties={
|
|
"function": function,
|
|
"file": file,
|
|
},
|
|
text="Enter:{} of {}".format(function, file)
|
|
)
|
|
|
|
async def log_exit(self, function: str, file: str, excution_time_in_ns: int):
|
|
return await super().log_event(
|
|
sender_id=self.event_sender_id,
|
|
receiver_id=self.event_receiver_id,
|
|
subject=self.event_subject,
|
|
event="exit",
|
|
properties={
|
|
"function": function,
|
|
"file": file,
|
|
"excution_time_in_ns": excution_time_in_ns
|
|
},
|
|
text="Exit:{} of {}".format(function, file)
|
|
)
|
|
|
|
async def log_exception(self, exception: Exception, function: str, file: str, excution_time_in_ns: int) -> None:
|
|
return await super().log_exception(
|
|
sender_id=self.event_sender_id,
|
|
receiver_id=self.event_receiver_id,
|
|
subject=self.event_subject,
|
|
exception=exception,
|
|
text="Exception:{} of {}".format(function, file),
|
|
properties={
|
|
"function": function,
|
|
"file": file,
|
|
"excution_time_in_ns": excution_time_in_ns
|
|
},
|
|
)
|