6.28. foundations.verbose

verbose.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines Foundations package verbose and logging objects.

Others:

6.28.1. Module Attributes

foundations.verbose.THREADS_IDENTIFIERS
foundations.verbose.INDENT_LEVEL
foundations.verbose.LOGGER
foundations.verbose.LOGGING_DEFAULT_FORMATTER
foundations.verbose.LOGGING_EXTENDED_FORMATTER
foundations.verbose.LOGGING_STANDARD_FORMATTER
foundations.verbose.TRACER_LOGGING_FUNCTION

6.28.2. Functions

foundations.verbose.toUnicode(data, encoding='utf-8', errors='ignore')[source]

Converts given data to unicode string using package default settings, fighting The Hell!

Usage:

>>> toUnicode("myData")
u'myData'
>>> toUnicode("汉字/漢字")
u'汉字/漢字'
Parameters:
  • data (object) – Data to convert.
  • encoding (unicode) – File encoding codec.
  • errors (unicode) – File encoding errors handling.
Returns:

Unicode data.

Return type:

unicode

foundations.verbose.indentMessage(message)[source]

Idents given message using the attr`INDENT_LEVEL` attribute value.

Parameters:message (unicode) – Message to indent.
Returns:indented message.
Return type:unicode
foundations.verbose.tracer(object)[source]
Traces execution.
Any method / definition decorated will have it’s execution traced through debug messages.
Both object entry and exit are logged.

Entering in an object:

INFO    : ---> foundations.environment.getUserApplicationDataDirectory() <<<---

Exiting from an object:

INFO   : <--- foundations.environment.getSystemApplicationDataDirectory() ^ '...' --->
Parameters:object (object) – Object to decorate.
Returns:Object.
Return type:object
foundations.verbose.installLogger(logger=None, module=None)[source]

Installs given logger in given module or default logger in caller introspected module.

Parameters:
  • logger (Logger) – Logger to install.
  • module (ModuleType) – Module.
Returns:

Logger.

Return type:

Logger

foundations.verbose.uninstallLogger(logger=None, module=None)[source]

Uninstalls given logger in given module or default logger in caller introspected module.

Parameters:
  • logger (Logger) – Logger to uninstall.
  • module (ModuleType) – Module.
Returns:

Definition success.

Return type:

bool

foundations.verbose.getLoggingConsoleHandler(logger=None, formatter=<logging.Formatter object at 0x102f6ef90>)[source]

Adds a logging console handler to given logger or default logger.

Parameters:
  • logger (Logger) – Logger to add the handler to.
  • formatter (Formatter) – Handler formatter.
Returns:

Added handler.

Return type:

Handler

foundations.verbose.getLoggingFileHandler(logger=None, file=None, formatter=<logging.Formatter object at 0x102f6ef90>)[source]

Adds a logging file handler to given logger or default logger using given file.

Parameters:
  • logger (Logger) – Logger to add the handler to.
  • file (unicode) – File to verbose into.
  • formatter (Formatter) – Handler formatter.
Returns:

Added handler.

Return type:

Handler

foundations.verbose.getLoggingStreamHandler(logger=None, formatter=<logging.Formatter object at 0x102f6ef90>)[source]

Adds a logging stream handler to given logger or default logger using given file.

Parameters:
  • logger (Logger) – Logger to add the handler to.
  • file (unicode) – File to verbose into.
  • formatter (Formatter) – Handler formatter.
Returns:

Added handler.

Return type:

Handler

foundations.verbose.removeLoggingHandler(handler, logger=None)[source]

Removes given logging handler from given logger.

Parameters:
  • handler (Handler) – Handler.
  • logger (Logger) – Handler logger.
Returns:

Definition success.

Return type:

bool

foundations.verbose.setVerbosityLevel(verbosityLevel=3, logger=None)[source]

Defines logging verbosity level.

Available verbosity levels:

0: Critical.
1: Error.
2: Warning.
3: Info.
4: Debug.
Parameters:
  • verbosityLevel (int) – Verbosity level.
  • logger (Logger) – Logger to set the verbosity level to.
Returns:

Definition success.

Return type:

bool

6.28.3. Classes

class foundations.verbose.Streamer(stream=None)[source]

Bases: object

Defines a stream object for logging.StreamHandler logging handler.

Initializes the class.

Parameters:stream (object) – Stream object.
stream[source]

Property for self.__stream attribute.

Returns:self.__stream.
Return type:list
write(message)[source]

Provides write ability to the class.

Parameters:message (unicode) – Current message.
flush()[source]

Flushes the current stream.

class foundations.verbose.StandardOutputStreamer(logger)[source]

Bases: object

Defines a redirection object intented to be used for sys.stdout and sys.stderr streams.
Logging messages will be written to given logger handlers.

Initializes the class.

Parameters:logger (object) – Logger.
logger[source]

Property for self.__logger attribute.

Returns:self.__logger.
Return type:Logger
write(message)[source]

Writes given message to logger handlers.

Parameters:message (unicode) – Message.
Returns:Method success.
Return type:bool