libics.env

libics.env.ASSUME_CONFIG_ITEM(key, val)
libics.env.ASSUME_DIR(*args)
libics.env.ASSUME_FILE(*args, copy_file=None)
libics.env.READ_JSON(file_path, obj=None)
libics.env.WRITE_CONFIG(copy_to_old=True)
libics.env.WRITE_JSON(file_path, obj)

constants

logging

class libics.env.logging.ColorFormatter(fmt=None, datefmt=None, style='%', validate=True)

Bases: logging.Formatter

Methods

converter([seconds])

Convert seconds since the Epoch to a time tuple expressing local time.

format(record)

Format the specified record as text.

formatException(ei)

Format and return the specified exception information as a string.

formatStack(stack_info)

This method is provided as an extension point for specialized formatting of stack information.

formatTime(record[, datefmt])

Return the creation time of the specified LogRecord as formatted text.

usesTime()

Check if the format uses the creation time of the record.

formatMessage

COLORS = {'CRITICAL': '\x1b[37m\x1b[41m', 'DEBUG': '\x1b[37m\x1b[2m', 'ERROR': '\x1b[31m', 'INFO': '\x1b[37m', 'WARNING': '\x1b[33m'}
format(record)

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.

class libics.env.logging.MaxFilter(maxlevel=100)

Bases: logging.Filter

Logging filter specifying the maximum log level to be handled.

Methods

filter(record)

Determine if the specified record is to be logged.

filter(record)

Determine if the specified record is to be logged.

Is the specified record to be logged? Returns 0 for no, nonzero for yes. If deemed appropriate, the record may be modified in-place.

libics.env.logging.get_logger(name, level=30)

Gets a named logger instance.

Parameters
namestr

Name of logger. Should be hierarchically dot-separated.

levelint

Default log level. Use one of DEBUG, INFO, WARNING, ERROR, CRITICAL.

Examples

>>> logger = get_logger("libics.core.my_module", level=logging.INFO)
>>> logger.error("some error occured")
2020-02-02 20:20,002 [libics.core.my_module] ERROR: some error occured
>>> logger.debug("some debug message")
>>> logger.setLevel(logging.DEBUG)
>>> logger.debug("some debug message")
2020-02-02 20:20,200 [libics.core.my_module] DEBUG: some debug message

system

libics.env.system.add_to_sys_path(path, index=None)

Adds ‘path’ to ‘sys.path’.

The ‘index’ specifies the path list position. If it is ‘None’, it will be appended. If ‘path’ is already in ‘sys.path’, ‘sys.path’ will not be changed, even if an index is specified.