2 File in charge of logging events into the logging database
4from typing
import List, Union, Dict, Any
6from display_tty
import Disp, TOML_CONF, FILE_DESCRIPTOR, SAVE_TO_FILE, FILE_NAME
8from ..components.runtime_data
import RuntimeData
9from ..components
import constants
as CONST
11from .
import constants
as ACONST
16 Class in charge of logging events into the logging database
19 def __init__(self, runtime_data: RuntimeData, success: int = 0, error: int = 84, debug: bool =
False) ->
None:
21 Class in charge of logging events into the logging database
24 runtime_data (RuntimeData): _description_
25 success (int, optional): _description_. Defaults to 0.
26 error (int, optional): _description_. Defaults to 84.
27 debug (bool, optional): _description_. Defaults to False.
41 logger=self.__class__.__name__
44 def log_event(self, log_type: str, action_id: int = 0, code: int = ACONST.CODE_ERROR, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
46 Log an event into the logging database
49 log_type (str): _description_: The type of the event
50 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
51 code (int, optional): _description_: The code of the event, defaults to ACONST.CODE_ERROR
52 message (Union[str, None], optional): _description_: The message of the event, defaults to None
53 resolved (bool, optional): _description_: The status of the event, defaults to False
56 int: _description_: Returns 0 if it succeeds, 84 otherwise
60 columns: List[str] = self.
runtime_data.database_link.get_table_column_names(
61 CONST.TAB_ACTION_LOGGING
63 if isinstance(columns, int)
is True and columns != self.
success:
64 self.
disp.
log_error(
"Failed to get the table columns.", title)
68 if log_type
not in ACONST.LIST_TYPE:
69 msg = f
"Type: {type} is not in the list of types."
70 msg += f
" Setting type to {ACONST.TYPE_UNKNOWN}."
72 log_type = ACONST.TYPE_UNKNOWN
75 msg = f
"The action_id, {action_id},"
76 msg +=
" is not in the Actions table."
82 if code
in ACONST.LOG_EQUIVALENCE:
83 code_level = ACONST.LOG_EQUIVALENCE[code]
85 code_level = ACONST.LOG_EQUIVALENCE[ACONST.CODE_UNKNOWN]
91 "The message is None, defaulting to the code message equivalence.", title
93 message = ACONST.LOG_MESSAGE_EQUIVALENCE[code_level]
97 if isinstance(resolved, bool)
is False:
99 "The resolved status is not a boolean, defaulting to False.", title
115 status = self.
runtime_data.database_link.insert_data_into_table(
116 table=CONST.TAB_ACTION_LOGGING,
128 Check if the action_id is in the Actions table
131 action_id (int, optional): _description_. Defaults to 0.: The id of the concerned action.
134 bool: _description_: Returns True if it is present, False otherwise.
136 title =
"_check_if_action_id_in_table"
138 data = self.
runtime_data.database_link.get_data_from_table(
139 table=CONST.TAB_ACTIONS,
141 where=f
"id='{action_id}'",
145 if isinstance(data, int)
is True and data != self.
success:
152 def log_info(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
154 Log an info event into the logging database
157 log_type (str): _description_: The type of the event
158 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
159 message (Union[str, None], optional): _description_: The message of the event, defaults to None
160 resolved (bool, optional): _description_: The status of the event, defaults to False
163 int: _description_: Returns self.success if it succeeds, self.error otherwise
168 code=ACONST.CODE_INFO,
173 def log_success(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
175 Log an success event into the logging database
178 log_type (str): _description_: The type of the event
179 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
180 message (Union[str, None], optional): _description_: The message of the event, defaults to None
181 resolved (bool, optional): _description_: The status of the event, defaults to False
184 int: _description_: Returns self.success if it succeeds, self.error otherwise
189 code=ACONST.CODE_SUCCESS,
194 def log_debug(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
196 Log an debug event into the logging database
199 log_type (str): _description_: The type of the event
200 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
201 message (Union[str, None], optional): _description_: The message of the event, defaults to None
202 resolved (bool, optional): _description_: The status of the event, defaults to False
205 int: _description_: Returns self.success if it succeeds, self.error otherwise
210 code=ACONST.CODE_DEBUG,
215 def log_warning(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
217 Log an warning event into the logging database
220 log_type (str): _description_: The type of the event
221 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
222 message (Union[str, None], optional): _description_: The message of the event, defaults to None
223 resolved (bool, optional): _description_: The status of the event, defaults to False
226 int: _description_: Returns self.success if it succeeds, self.error otherwise
231 code=ACONST.CODE_WARNING,
236 def log_error(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
238 Log an error event into the logging database
241 log_type (str): _description_: The type of the event
242 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
243 message (Union[str, None], optional): _description_: The message of the event, defaults to None
244 resolved (bool, optional): _description_: The status of the event, defaults to False
247 int: _description_: Returns self.success if it succeeds, self.error otherwise
252 code=ACONST.CODE_ERROR,
257 def log_critical(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
259 Log an critical event into the logging database
262 log_type (str): _description_: The type of the event
263 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
264 message (Union[str, None], optional): _description_: The message of the event, defaults to None
265 resolved (bool, optional): _description_: The status of the event, defaults to False
268 int: _description_: Returns self.success if it succeeds, self.error otherwise
273 code=ACONST.CODE_CRITICAL,
278 def log_fatal(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
280 Log an fatal event into the logging database
283 log_type (str): _description_: The type of the event
284 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
285 message (Union[str, None], optional): _description_: The message of the event, defaults to None
286 resolved (bool, optional): _description_: The status of the event, defaults to False
289 int: _description_: Returns self.success if it succeeds, self.error otherwise
294 code=ACONST.CODE_FATAL,
299 def log_unknown(self, log_type: str, action_id: int = 0, message: Union[str,
None] =
None, resolved: bool =
False) -> int:
301 Log an unknown event into the logging database
304 log_type (str): _description_: The type of the event
305 action_id (int, optional): _description_: The id of the action that triggered the event, defaults to 0
306 message (Union[str, None], optional): _description_: The message of the event, defaults to None
307 resolved (bool, optional): _description_: The status of the event, defaults to False
310 int: _description_: Returns self.success if it succeeds, self.error otherwise
315 code=ACONST.CODE_UNKNOWN,
320 def get_logs(self, action_id: Union[int,
None] =
None, code: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
322 Get the logs from the database
325 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
326 code (Union[int, None], optional): _description_: Specify a code to narrow down the results.
327 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
330 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
334 if action_id
is not None:
335 where.append(f
"action_id='{action_id}'")
337 where.append(f
"code='{code}'")
341 data = self.
runtime_data.database_link.get_data_from_table(
342 table=CONST.TAB_ACTION_LOGGING,
348 if isinstance(data, int)
is True and data != self.
success:
353 def get_logs_unknown(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
355 Get the unknown logs from the database
358 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
359 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
362 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
366 code=ACONST.CODE_UNKNOWN,
370 def get_logs_info(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
372 Get the info logs from the database
375 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
376 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
379 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
383 code=ACONST.CODE_INFO,
387 def get_logs_success(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
389 Get the success logs from the database
392 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
393 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
396 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
400 code=ACONST.CODE_SUCCESS,
404 def get_logs_debug(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
406 Get the debug logs from the database
409 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
410 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
413 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
417 code=ACONST.CODE_DEBUG,
421 def get_logs_warning(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
423 Get the warning logs from the database
426 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
427 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
430 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
434 code=ACONST.CODE_WARNING,
438 def get_logs_error(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
440 Get the error logs from the database
443 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
444 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
447 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
451 code=ACONST.CODE_ERROR,
455 def get_logs_critical(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
457 Get the critical logs from the database
460 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
461 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
464 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
468 code=ACONST.CODE_CRITICAL,
472 def get_logs_fatal(self, action_id: Union[int,
None] =
None, beautify: bool =
True) -> Union[List[Union[Dict[str, Any], List[Any]]], int]:
474 Get the fatal logs from the database
477 action_id (Union[int, None], optional): _description_: Specify an action id to narrow down the results.
478 beautify (bool, optional): _description_: Set to True if you wish to beautify the output
481 Union[List[Dict[str, Any]], int]: _description_: Returns the logs if it succeeds, self.error otherwise
485 code=ACONST.CODE_FATAL,
int log_error(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
int log_critical(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
int log_unknown(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_warning(self, Union[int, None] action_id=None, bool beautify=True)
int log_warning(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_unknown(self, Union[int, None] action_id=None, bool beautify=True)
int log_fatal(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_critical(self, Union[int, None] action_id=None, bool beautify=True)
bool _check_if_action_id_in_table(self, int action_id=0)
int log_info(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_error(self, Union[int, None] action_id=None, bool beautify=True)
int log_success(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_debug(self, Union[int, None] action_id=None, bool beautify=True)
None __init__(self, RuntimeData runtime_data, int success=0, int error=84, bool debug=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_info(self, Union[int, None] action_id=None, bool beautify=True)
int log_debug(self, str log_type, int action_id=0, Union[str, None] message=None, bool resolved=False)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs(self, Union[int, None] action_id=None, Union[int, None] code=None, bool beautify=True)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_success(self, Union[int, None] action_id=None, bool beautify=True)
Union[List[Union[Dict[str, Any], List[Any]]], int] get_logs_fatal(self, Union[int, None] action_id=None, bool beautify=True)
int log_event(self, str log_type, int action_id=0, int code=ACONST.CODE_ERROR, Union[str, None] message=None, bool resolved=False)