agent0.hyperlogs ================ .. py:module:: agent0.hyperlogs .. autoapi-nested-parse:: Logging setup and defaults .. !! processed by numpydoc !! Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/agent0/hyperlogs/json_encoder/index /autoapi/agent0/hyperlogs/logs/index /autoapi/agent0/hyperlogs/logs_test/index /autoapi/agent0/hyperlogs/rollbar_utilities/index Attributes ---------- .. autoapisummary:: agent0.hyperlogs.DEFAULT_LOG_DATETIME agent0.hyperlogs.DEFAULT_LOG_FORMATTER agent0.hyperlogs.DEFAULT_LOG_LEVEL agent0.hyperlogs.DEFAULT_LOG_MAXBYTES Classes ------- .. autoapisummary:: agent0.hyperlogs.ExtendedJSONEncoder Functions --------- .. autoapisummary:: agent0.hyperlogs.add_file_handler agent0.hyperlogs.add_stdout_handler agent0.hyperlogs.close_logging agent0.hyperlogs.get_root_logger agent0.hyperlogs.setup_logging Package Contents ---------------- .. py:class:: ExtendedJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None) Bases: :py:obj:`json.JSONEncoder` Custom encoder for JSON string dumps. .. !! processed by numpydoc !! .. py:method:: default(o: Any) -> Any Override default behavior. :param o: The object to be converted to JSON. :type o: Any :returns: The corresponding object ready to be serialized to JSON. :rtype: Any .. !! processed by numpydoc !! .. py:data:: DEFAULT_LOG_DATETIME :value: '%y-%m-%d %H:%M:%S' .. py:data:: DEFAULT_LOG_FORMATTER :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ %(asctime)s: %(levelname)s: %(filename)s:%(lineno)s::%(module)s::%(funcName)s: %(message)s""" .. raw:: html
.. py:data:: DEFAULT_LOG_LEVEL :value: 20 .. py:data:: DEFAULT_LOG_MAXBYTES :value: 0 .. py:function:: add_file_handler(log_filename: str, logger: logging.Logger | None = None, delete_previous_logs: bool = False, log_format_string: str | None = None, log_level: int | None = logging.INFO, max_bytes=None, keep_previous_handlers: bool = True) Add a file handler to the root logger. :param log_filename: Path and name of the log file. :type log_filename: str :param logger: Logger to which to add the handler. Defaults to get_root_logger(). :type logger: logging.Logger, optional :param delete_previous_logs: Whether to delete previous log file if it exists. Defaults to False. :type delete_previous_logs: bool, optional :param log_format_string: Logging format described in string format. :type log_format_string: str, optional :param log_level: Log level to track. Defaults to hyperlogs.DEFAULT_LOG_LEVEL. :type log_level: int, optional :param max_bytes: Maximum size of the log file in bytes. Defaults to hyperlogs.DEFAULT_LOG_MAXBYTES. :type max_bytes: int, optional :param keep_previous_handlers: Whether to keep previous handlers. Defaults to True. :type keep_previous_handlers: bool, optional .. !! processed by numpydoc !! .. py:function:: add_stdout_handler(logger: logging.Logger | None = None, log_format_string: str | None = None, log_level: int | None = logging.INFO, keep_previous_handlers: bool = True) -> None Add a stdout handler to the root logger. :param logger: Logger to which to add the handler. Defaults to get_root_logger(). :type logger: logging.Logger, optional :param log_format_string: Logging format described in string format. Defaults to hyperlogs.DEFAULT_LOG_FORMAT and hyperlogs.DEFAULT_LOG_DATETIME. :type log_format_string: str, optional :param log_level: Log level to track. Defaults to hyperlogs.DEFAULT_LOG_LEVEL. :type log_level: int, optional :param keep_previous_handlers: Whether to keep previous handlers. Defaults to True. :type keep_previous_handlers: bool, optional .. !! processed by numpydoc !! .. py:function:: close_logging(delete_logs=True) -> None Close logging and remove handlers for the test. :param delete_logs: Whether to delete logs before closing logging. :type delete_logs: bool .. !! processed by numpydoc !! .. py:function:: get_root_logger(root_logger: logging.Logger | None = None) -> logging.Logger Retrieve root logger, isolated from other loggers (like pytest). :param root_logger: Logger to which to add the handler. Defaults to logging.getLogger(). :type root_logger: logging.Logger, optional :returns: Root logger. :rtype: logging.Logger .. !! processed by numpydoc !! .. py:function:: setup_logging(log_filename: str | None = None, max_bytes: int | None = None, log_level: int | None = None, delete_previous_logs: bool = False, log_stdout: bool = True, log_format_string: str | None = None, keep_previous_handlers: bool = False) -> None Set up basic logging with default settings, customized by inputs. This function should only be run once, as it implements the default settings. To customize logging behavior, only add_stdout_handler or add_file_handler should be run. The log_filename can be a path to the log file. If log_filename is not provided, log_file_and_stdout can be set to True to log to both file and standard output (console). If neither log_filename nor log_file_and_stdout is specified, the log messages will be sent to standard output only. :param log_filename: Path and name of the log file. :type log_filename: str, optional :param max_bytes: Maximum size of the log file in bytes. Defaults to hyperlogs.DEFAULT_LOG_MAXBYTES. :type max_bytes: int, optional :param log_level: Log level to track. Defaults to hyperlogs.DEFAULT_LOG_LEVEL. :type log_level: int, optional :param delete_previous_logs: Whether to delete previous log file if it exists. Defaults to False. :type delete_previous_logs: bool, optional :param log_stdout: Whether to log to standard output. Defaults to True. :type log_stdout: bool, optional :param log_format_string: Log formatter object. Defaults to None. :type log_format_string: str, optional :param keep_previous_handlers: Whether to keep previous handlers. Defaults to False. :type keep_previous_handlers: bool, optional :param .. todo::: - Test the various optional input combinations .. !! processed by numpydoc !!