certdeploy package

Subpackages

Submodules

certdeploy.errors module

Module contents

Shared CertDeploy code.

class certdeploy.LogLevel(value)[source]

Bases: Enum

Logging levels and utilities.

CRITICAL = 'CRITICAL'
DEBUG = 'DEBUG'
ERROR = 'ERROR'
INFO = 'INFO'
WARNING = 'WARNING'
classmethod cast(level: int | str | LogLevel) LogLevel[source]

Cast level to a LogLevel.

Returns:

A LogLevel corresponding to level.

Raises:

TypeError – When level does not correspond to any LogLevel.

classmethod validate(level: int | str | LogLevel) bool[source]

Verify level is a valid LogLevel or equivalent.

Parameters:

level – A log level.

Returns:

True if level is a log level.

class certdeploy.Logger(name: str)[source]

Bases: object

A logging helper with some modified behavior.

Parameters:

name – The name of the logging.Logger.

error(*args: Any, exc_info=None, **kwargs)[source]

Log an error message.

See logging.error for details. This method differs from logging.error in the following ways:

  • If the first argument is an exception it’s formatted so the type

    is given and not just the message.

  • exc_info is ignored if the log level is anything but DEBUG.

classmethod fromLogger(logger: Logger) Logger[source]

Create a Logger from a logging.Logger.

Parameters:

logger – The source logging.Logger.

Returns:

A new Logger with logger as the wrapped logger.

purgeHandlers()[source]

Purge all handlers from the logger.

setLevel(level: int | str | LogLevel)[source]

Set the logging level for this Logger.

This is a more flexible implementation of logging.Logger.setLevel.

Parameters:

level – The desired log level as either the logging log level, the string log level, or the LogLevel.

certdeploy.format_error(err: Exception, message_format: str = '{name}: {message}') str[source]

Format errors consistently.

Parameters:
  • err – The exception to format.

  • message_format – The format string (.format style) to apply the error to. The keys name and message are passed to the format string. Defaults to ‘{name}: {message}’.

Returns:

A formatted string with the name and message of the given error.

certdeploy.set_log_properties(logger_name: str, log_filename: PathLike, log_level: int | str | LogLevel | None = None, msg_format: str = '%(levelname)s:%(name)s: %(message)s', date_format: str = '%Y.%m.%d-%H:%M:%S')[source]

Set logger properties.

Parameters:
  • logger_name – The name of the logger.

  • log_filename – The path to the log file.

  • log_level – The desired log level. Defaults to LogLevel.ERROR.

  • msg_format – The format for the each log entry. Defaults to DEFAULT_LOG_FORMAT.

  • date_format – The date format for each log entry. This is only used if the msg_format has the date in it. Defaults to DEFAULT_LOG_DATE_FORMAT.

certdeploy.set_paramiko_log_properties(log_filename: PathLike | None = None, log_level: int | str | LogLevel | None = None, msg_format: str = '%(levelname)s:%(name)s: %(message)s', date_format: str = '%Y.%m.%d-%H:%M:%S')[source]

Set the paramiko logger properties.

Parameters:
  • log_filename – The path to the log file.

  • log_level – The desired log level. Defaults to LogLevel.ERROR.

  • msg_format – The format for the each log entry. Defaults to DEFAULT_LOG_FORMAT.

  • date_format – The date format for each log entry. This is only used if the msg_format has the date in it. Defaults to DEFAULT_LOG_DATE_FORMAT.