5.8. logs

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: object, level: Union[str, int, None] = None, **kwargs) → logging.Logger[source]

Get a child logger for an object.

Notes

Parameters:
  • obj (object) – object to get a logger for
  • level (str or int, optional) – default None - level to set
  • **kwargs
    • logger (logging.Logger): default module of class of obj - logger to get child from
Returns:

created logger child obj

Return type:

logging.Logger

axonius_api_client.logs.set_log_level(obj: Union[logging.Logger, logging.Handler], level: Union[str, int, None] = None)[source]

Set a logger or handler to a log level.

Notes

Parameters:
axonius_api_client.logs.str_level(level: Union[int, str]) → str[source]

Get a logging level in str format.

Parameters:level (str or int) – level to get str format of
Returns:str repr of logging level
Return type:str
Raises:ToolsError – if level is not mappable as an int or str to known logger level in logging
axonius_api_client.logs.add_stderr(obj: logging.Logger, level: Union[int, str] = 'debug', hname: str = 'handler_stderr', fmt: str = '%(levelname)-8s [%(name)s] %(message)s', datefmt: str = '%m/%d/%Y %I:%M:%S %p %Z') → logging.StreamHandler[source]

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

Parameters:
  • obj (logging.Logger) – logger obj to add handler to
  • **kwargs
    • level (logging.Logger): default: axonius_api_client.LOG_LEVEL_CONSOLE - log level to assign to handler
    • hname (str): default: axonius_api_client.LOG_NAME_STDERR - name to assign to handler
    • fmt (str): default: axonius_api_client.LOG_FMT_CONSOLE - logging format to use
    • datefmt (str): default: axonius_api_client.LOG_DATEFMT_CONSOLE - date format to use
Returns:

handler that was added to logger obj

Return type:

logging.StreamHandler

axonius_api_client.logs.add_stdout(obj: logging.Logger, level: Union[int, str] = 'debug', hname: str = 'handler_stdout', fmt: str = '%(levelname)-8s [%(name)s] %(message)s', datefmt: str = '%m/%d/%Y %I:%M:%S %p %Z') → logging.StreamHandler[source]

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

Parameters:
  • obj (logging.Logger) – logger obj to add handler to
  • **kwargs
    • level (logging.Logger): default: axonius_api_client.LOG_LEVEL_CONSOLE - log level to assign to handler
    • hname (str): default: axonius_api_client.LOG_NAME_STDOUT - name to assign to handler
    • fmt (str): default: axonius_api_client.LOG_FMT_CONSOLE - logging format to use
    • datefmt (str): default: axonius_api_client.LOG_DATEFMT_CONSOLE - date format to use
Returns:

handler that was added to logger obj

Return type:

logging.StreamHandler

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

Add a RotatingFileHandler to a logger object.

Parameters:
  • obj (logging.Logger) – logger obj to add handler to
  • **kwargs
    • level (logging.Logger): default: axonius_api_client.LOG_LEVEL_FILE - log level to assign to handler
    • hname (str): default: axonius_api_client.LOG_NAME_FILE - name to assign to handler
    • fmt (str): default: axonius_api_client.LOG_FMT_FILE - logging format to use
    • datefmt (str): default: axonius_api_client.LOG_DATEFMT_FILE - date format to use
    • file_path (str): default: axonius_api_client.LOG_FILE_PATH - path to write file_name to
    • file_name (str): default: axonius_api_client.LOG_FILE_NAME - name of file to write log entries to
    • file_path_mode (oct): default: axonius_api_client.LOG_FILE_PATH_MODE - permissions to assign to directory for log file if it has to be created
    • max_mb (int): default: axonius_api_client.LOG_FILE_MAX_MB - rollover trigger in MB
    • max_files (int): default: axonius_api_client.LOG_FILE_MAX_FILES - max files to keep for rollover
Returns:

handler that was added to logger obj

Return type:

logging.StreamHandler

axonius_api_client.logs.add_null(obj: logging.Logger, traverse: bool = True, hname='NULL') → Optional[logging.NullHandler][source]

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

Parameters:
  • obj (logging.Logger) – logger obj to add handler to
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any nullhandlers attached
    • if False only check the logger obj supplied
  • **kwargs
    • hname (str): default: NULL - name to assign to handler
Returns:

handler that was added to logger obj

Return type:

logging.NullHandler

axonius_api_client.logs.add_handler(obj: logging.Logger, htype: logging.Handler, level: Union[str, int], hname: str, fmt: str, datefmt: str, **kwargs) → logging.Handler[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 (str) – 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
Returns:

handler that was created and added

Return type:

logging.Handler

axonius_api_client.logs.del_stderr(obj: logging.Logger, traverse: bool = True, hname: str = 'handler_stderr') → Dict[str, List[logging.Handler]][source]

Remove the STDERR StreamHandler from a logger if found.

Parameters:
  • obj (logging.Logger) – logger obj to remove handler from
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any attached handlers named with hname
    • if False only check the logger obj supplied for handlers named with hname
  • **kwargs
    • hname (str): default: axonius_api_client.LOG_NAME_FILE - name of handler to search for and remove
Returns:

dict handler handler name->[handler objects] mapping of found and removed handlers

Return type:

logging.Handler

axonius_api_client.logs.del_stdout(obj: logging.Logger, traverse: bool = True, hname: str = 'handler_stdout') → Dict[str, List[logging.Handler]][source]

Remove the STDOUT StreamHandler from a logger if found.

Parameters:
  • obj (logging.Logger) – logger obj to remove handler from
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any attached handlers named with hname
    • if False only check the logger obj supplied for handlers named with hname
  • **kwargs
    • hname (str): default: axonius_api_client.LOG_NAME_STDOUT - name of handler to search for and remove
Returns:

dict handler handler name->[handler objects] mapping of found and removed handlers

Return type:

logging.Handler

axonius_api_client.logs.del_file(obj: logging.Logger, traverse: bool = True, hname='handler_file') → Dict[str, List[logging.Handler]][source]

Remove the RotatingFileHandler from a logger if found.

Parameters:
  • obj (logging.Logger) – logger obj to remove handler from
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any attached handlers named with hname
    • if False only check the logger obj supplied for handlers named with hname
  • **kwargs
    • hname (str): default: axonius_api_client.LOG_NAME_FILE - name of handler to search for and remove
Returns:

dict handler handler name->[handler objects] mapping of found and removed handlers

Return type:

logging.Handler

axonius_api_client.logs.del_null(obj: logging.Logger, traverse: bool = True, hname: str = 'NULL') → Dict[str, List[logging.Handler]][source]

Remove the NullHandler from a logger if found.

Parameters:
  • obj (logging.Logger) – logger obj to remove handler from
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any attached handlers named with hname
    • if False only check the logger obj supplied for handlers named with hname
  • **kwargs
    • hname (str): default: NULL - name of handler to search for and remove
Returns:

dict handler handler name->[handler objects] mapping of found and removed handlers

Return type:

logging.Handler

axonius_api_client.logs.del_handler(obj: logging.Logger, hname: str = '', htype: logging.Handler = None, traverse: bool = True) → Dict[str, List[logging.Handler]][source]

Remove the NullHandler from a logger if found.

Parameters:
  • obj (logging.Logger) – logger obj to remove handler from
  • hname (str, optional) – default "" - name of handler to find and remove
  • htype (object, optional) – default None - type of handler to find and remove
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any attached handlers named with hname
    • if False only check the logger obj supplied for handlers named with hname
Returns:

dict handler handler name->[handler objects] mapping of found and removed handlers

axonius_api_client.logs.find_handlers(obj: logging.Logger, hname: str = '', htype: logging.Handler = None, traverse: bool = True) → Dict[str, List[logging.Handler]][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:
  • obj (logging.Logger) – logger obj to remove handler from
  • hname (str, optional) – default "" - name of handler to find and remove
  • htype (object, optional) – default None - type of handler to find and remove
  • traverse (bool, optional) –

    default True -

    • if True traverse the logger obj supplied up to the root logger to see if there are any matching attached handlers
    • if False only check the logger obj supplied for any matching attached handlers
Returns:

dict handler handler name->[handler objects] mapping of found handlers

axonius_api_client.logs.LOG = <Logger axonius_api_client (DEBUG)>

root logger used by entire package, named after package.

Type:logging.Logger
axonius_api_client.logs.handle_unhandled_exception(exc_type, exc_value, exc_traceback)[source]

Log unhandled exceptions.