zea.log¶
Custom zea
python logging module.
Wrapper around python logging module to provide a simple interface for logging both to the console and to a file with color support.
Example usage¶
from zea import log
log.info("This is an info message")
path = "data/datafile.hdf5"
log.info(f"Saved to {log.yellow(path)}")
Functions
|
Adds ANSI escape codes to print a string in blue around the string. |
|
Adds ANSI escape codes to print a string in bold around the string. |
|
Configures a simple console logger with the givel level. |
|
Configures a simple console logger with the givel level. |
|
Prints a message with log level critical. |
|
Adds ANSI escape codes to print a string in cyan around the string. |
|
Adds ANSI escape codes to print a string in blue around the string. |
|
Prints a message with log level debug. |
|
Prints a message with custom log level DEPRECATED. |
Enables file logging |
|
|
Prints a message with log level error. |
|
Returns the format function for the given format name. |
|
Adds ANSI escape codes to print a string in green around the string. |
|
Prints a message with log level info. |
|
Adds ANSI escape codes to print a string in magenta around the string. |
|
Formats a number to a string with the given number of decimals. |
|
Adds ANSI escape codes to print a string in orange around the string. |
|
Adds ANSI escape codes to print a string in purple around the string. |
|
Adds ANSI escape codes to print a string in red around the string. |
Removes ANSI color escape codes from the given string. |
|
|
Sets the log level of the logger. |
|
Context manager to temporarily set the log level for the logger. |
|
Prints a message to the console in green. |
|
Prints a message with log level warning. |
|
Adds ANSI escape codes to print a string in white around the string. |
|
Adds ANSI escape codes to print a string in yellow around the string. |
Classes
|
Custom formatter to use different format strings for different log levels |
- class zea.log.CustomFormatter(name=None, color=True, name_color='darkgreen')[source]¶
Bases:
Formatter
Custom formatter to use different format strings for different log levels
- format(record)[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.
- zea.log.configure_console_logger(level='INFO', name=None, color=True, name_color='darkgreen')[source]¶
Configures a simple console logger with the givel level. A usecase is to change the formatting of the default handler of the root logger
- zea.log.configure_file_logger(level='INFO')[source]¶
Configures a simple console logger with the givel level. A usecase is to change the formatting of the default handler of the root logger
- zea.log.darkgreen(string)[source]¶
Adds ANSI escape codes to print a string in blue around the string.
- zea.log.deprecated(message, *args, **kwargs)[source]¶
Prints a message with custom log level DEPRECATED.
- zea.log.magenta(string)[source]¶
Adds ANSI escape codes to print a string in magenta around the string.
- zea.log.number_to_str(number, decimals=2)[source]¶
Formats a number to a string with the given number of decimals.
- zea.log.orange(string)[source]¶
Adds ANSI escape codes to print a string in orange around the string.
- zea.log.purple(string)[source]¶
Adds ANSI escape codes to print a string in purple around the string.
- zea.log.remove_color_escape_codes(text)[source]¶
Removes ANSI color escape codes from the given string.
- zea.log.set_level(level)[source]¶
Context manager to temporarily set the log level for the logger.
Also sets the log level for the file logger if it exists.
Example
>>> from zea import log >>> with log.set_level("WARNING"): ... log.info("This will not be shown") ... log.warning("This will be shown")
- Parameters:
level (str or int) – The log level to set temporarily (e.g., “DEBUG”, “INFO”, logging.WARNING).
- Yields:
None