4.7.5.4. Logging utilities

Logging utilities.

axonius_api_client.logs.gmtime()[source]

Set the logging system to use GMT for time strings.

axonius_api_client.logs.localtime()[source]

Set the logging system to use local time for time strings.

axonius_api_client.logs.get_obj_log(obj, level=None, **kwargs)[source]

Get a child logger for an object.

Parameters
Return type

logging.Logger

axonius_api_client.logs.set_log_level(obj, level=None)[source]

Set a logger or handler to a log level.

Parameters
axonius_api_client.logs.str_level(level)[source]

Get a logging level in str format.

Parameters

level (typing.Union[int, str]) – level to get str format of

Raises

ToolsError – if level is not mappable as an int or str to a known logger level

Return type

str

axonius_api_client.logs.add_stderr(obj, level='debug', hname='handler_stderr', fmt='%(levelname)-8s %(module)-15s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p %Z')[source]

Add a StreamHandler to a logger object that outputs to STDERR.

Parameters
  • obj (logging.Logger) – logger obj to add handler to

  • level (typing.Union[int, str]) – log level to assign to handler

  • hname (str) – name to assign to handler

  • fmt (str) – logging format to use

  • datefmt (str) – date format to use

Return type

logging.StreamHandler

axonius_api_client.logs.add_stdout(obj, level='debug', hname='handler_stdout', fmt='%(levelname)-8s %(module)-15s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p %Z')[source]

Add a StreamHandler to a logger object that outputs to STDOUT.

Parameters
  • obj (logging.Logger) – logger obj to add handler to

  • level (typing.Union[int, str]) – log level to assign to handler

  • hname (str) – name to assign to handler

  • fmt (str) – logging format to use

  • datefmt (str) – date format to use

Return type

logging.StreamHandler

axonius_api_client.logs.add_file(obj, level='debug', hname='handler_file', file_path='/home/docs/checkouts/readthedocs.org/user_builds/axonius-api-client/checkouts/develop/docs', file_name='axonius_api_client.log', file_path_mode=448, max_mb=5, max_files=5, fmt='%(asctime)s %(levelname)-8s [%(name)s:%(funcName)s:%(pathname)s:%(lineno)d] %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p %Z')[source]

Add a RotatingFileHandler to a logger object.

Parameters
  • obj (logging.Logger) – logger obj to add handler to

  • level (typing.Union[int, str]) – log level to assign to handler

  • hname (str) – name to assign to handler

  • fmt (str) – logging format to use

  • datefmt (str) – date format to use

  • file_path (typing.Union[pathlib.Path, str]) – path to write file_name to

  • file_name (typing.Union[pathlib.Path, str]) – name of file to write log entries to

  • file_path_mode – permissions to assign to directory for log file when created

  • max_mb (int) – rollover trigger in MB

  • max_files (int) – max files to keep for rollover

Return type

logging.handlers.RotatingFileHandler

axonius_api_client.logs.add_null(obj, traverse=True, hname='NULL')[source]

Add a NullHandler to a logger if it has no handlers.

Parameters
  • obj (logging.Logger) – logger obj to add handler to

  • traverse (bool) – traverse the logger obj supplied up to the root logger

  • hname – name to assign to handler

Return type

typing.Optional[logging.NullHandler]

axonius_api_client.logs.add_handler(obj, htype, level, hname, fmt, datefmt, **kwargs)[source]

Add a handler to a logger obj.

Parameters
  • obj (logging.Logger) – logger obj to add handler to

  • htype (logging.Handler) – handler class to instantiate

  • level (typing.Union[str, int]) – level to assign to handler obj

  • hname (str) – name to assign to handler obj

  • fmt (str) – logging format to assign to handler obj

  • datefmt (str) – date format to assign to handler obj

  • **kwargs – passed to instantiation of htype

Return type

logging.Handler

axonius_api_client.logs.del_stderr(obj, traverse=True, hname='handler_stderr')[source]

Remove the STDERR StreamHandler from a logger if found.

Parameters
  • obj (logging.Logger) – logger obj to remove handler from

  • traverse (bool) – traverse the logger obj supplied up to the root logger

  • hname (str) – name of handler to search for and remove

Return type

typing.Dict[str, typing.List[logging.Handler]]

axonius_api_client.logs.del_stdout(obj, traverse=True, hname='handler_stdout')[source]

Remove the STDOUT StreamHandler from a logger if found.

Parameters
  • obj (logging.Logger) – logger obj to remove handler from

  • traverse (bool) – traverse the logger obj supplied up to the root logger

  • hname (str) – name of handler to search for and remove

Return type

typing.Dict[str, typing.List[logging.Handler]]

axonius_api_client.logs.del_file(obj, traverse=True, hname='handler_file')[source]

Remove the RotatingFileHandler from a logger if found.

Parameters
  • obj (logging.Logger) – logger obj to remove handler from

  • traverse (bool) – traverse the logger obj supplied up to the root logger

  • hname – name of handler to search for and remove

Return type

typing.Dict[str, typing.List[logging.Handler]]

axonius_api_client.logs.del_null(obj, traverse=True, hname='NULL')[source]

Remove the NullHandler from a logger if found.

Parameters
  • obj (logging.Logger) – logger obj to remove handler from

  • traverse (bool) – traverse the logger obj supplied up to the root logger

  • hname (str) – name of handler to search for and remove

Return type

typing.Dict[str, typing.List[logging.Handler]]

axonius_api_client.logs.del_handler(obj, hname='', htype=None, traverse=True)[source]

Remove the NullHandler from a logger if found.

Parameters
  • obj (logging.Logger) – logger obj to remove handler from

  • traverse (bool) – traverse the logger obj supplied up to the root logger

  • hname (str) – name of handler to search for and remove

  • htype (typing.Optional[logging.Handler]) – type of handler to find and remove

Return type

typing.Dict[str, typing.List[logging.Handler]]

axonius_api_client.logs.find_handlers(obj, hname='', htype=None, traverse=True)[source]

Remove the NullHandler from a logger if found.

Notes

  • will remove handler if hname supplied and handler obj name matches

  • will remove handler if htype supplied and handler obj type matches

Parameters
Return type

typing.Dict[str, typing.List[logging.Handler]]

axonius_api_client.logs.handle_unhandled_exception(exc_type, exc_value, exc_traceback)[source]

Log unhandled exceptions.