qsprpred.logs package
Submodules
qsprpred.logs.config module
- class qsprpred.logs.config.LevelFilter(level)[source]
Bases:
Filter
LoggingFilter used to filter one or more specific log levels messages
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
- class qsprpred.logs.config.LevelFormatter(formats: dict[int, str], **kwargs)[source]
Bases:
Formatter
LoggingFormatter used to specifiy the formatting per level
Initialize the formatter with specified format strings.
Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.
Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting,
str.format()
({}
) formatting orstring.Template
formatting in your format string.Changed in version 3.2: Added the
style
parameter.- converter()
- localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,
tm_sec,tm_wday,tm_yday,tm_isdst)
Convert seconds since the Epoch to a time tuple expressing local time. When ‘seconds’ is not passed in, convert the current time instead.
- default_msec_format = '%s,%03d'
- default_time_format = '%Y-%m-%d %H:%M:%S'
- format(record: LogRecord) str [source]
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- formatException(ei)
Format and return the specified exception information as a string.
This default implementation just uses traceback.print_exception()
- formatMessage(record)
- formatStack(stack_info)
This method is provided as an extension point for specialized formatting of stack information.
The input data is a string as returned from a call to
traceback.print_stack()
, but with the last trailing newline removed.The base implementation just returns the value passed in.
- formatTime(record, datefmt=None)
Return the creation time of the specified LogRecord as formatted text.
This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.
- usesTime()
Check if the format uses the creation time of the record.
- qsprpred.logs.config.config_logger(log_file_path, debug=None, disable_existing_loggers=True)[source]
Function to configure the logging. All info is saved in a simple format on the log file path. Debug entries are saved to a separate file if debug is True Debug and warning and above are save in a verbose format. Warning and above are also printed to std.out
- qsprpred.logs.config.get_git_info()[source]
Get information of the current git commit
If the package is installed with pip, read the detailed version extracted by setuptools_scm. Otherwise, use gitpython to get the information from the git repo.
qsprpred.logs.utils module
- qsprpred.logs.utils.backup_files_in_folder(_dir: str, backup_id: int, output_prefixes, output_extensions='dummy', cp_suffix=None)[source]
Backs up files in a specified directory to a backup directory.
- Parameters:
_dir (str) – The directory path where the files to be backed up are located.
backup_id (int) – The ID of the backup.
output_prefixes (str) – The prefix of the output files to be backed up.
output_extensions (str, optional) – The extension of the output files to be backed up. Defaults to “dummy”.
cp_suffix (list of str, optional) – The suffix of the files to be copied instead of moved. Defaults to None.
- Returns:
- A message indicating which files were backed up and where they
were moved/copied.
- Return type:
- qsprpred.logs.utils.enable_file_logger(log_folder: str, filename: str, debug: bool = False, log_name: str | None = None, init_data: dict | None = None, disable_existing_loggers: bool = False)[source]
Enable file logging.
- Parameters:
log_folder (str) – path to the folder where the log file should be stored
filename (str) – name of the log file
debug (bool) – whether to enable debug logging. Defaults to False.
log_name (str, optional) – name of the logger. Defaults to None.
init_data (dict, optional) – initial data to be logged. Defaults to None.
disable_existing_loggers (bool) – whether to disable existing loggers.
- qsprpred.logs.utils.export_conda_environment(filepath: str)[source]
Export the conda environment to a yaml file.
- Parameters:
filepath (str) – path to the yaml file
- Raises:
subprocess.CalledProcessError – if the command fails
Exception – if an unexpected error occurs