Public Member Functions | List of all members
minx.core.config.config Class Reference

Attributes for simple customizations. More...

Public Member Functions

def __init__
 Default values for various settings. More...
 
def log_to_console
 Send log messages to STDERR. More...
 
def log_to_file
 Send log messages to a file. More...
 
def log_level
 Set the level of logging verbosity. More...
 

Detailed Description

Attributes for simple customizations.

This class has the following attributes to allow simple customizations. In the list below, the parenthesized term specifies the type of the attribute and the term in square brackets is the attribute's default value.

Focus-related Customizations

Logging Configuration

To enable logging, use either log_to_console() to send log messages to STDERR or log_to_file() to send them to a file. You can also use log_level() to configure the level of verbosity.

The above three functions should be enough to configure logging for the most common cases. However, you can further customize logging by retrieving the keys of the logger dict and reassigning them to the desired values. The following paragraphs provide some details.

logger['formatters']['minx_formatter'] will get you a reference to the formatter for Minx's log messages. This formatter is itself a dict with the keys 'format' and 'datefmt'. Consult the Python logging documentation for further details about formatters.

logger['handlers']['minx_handler'] yields Minx's logging handler, which is also a dict with keys 'class' and 'formatter'. As mentioned above, the handler's 'class' is 'logging.NullHandler'. The value of the 'formatter' key is 'minx_formatter'. You should reset 'class' to another logging handler class (e.g., 'logging.FileHandler'). You should also set other keys appropriately. Consult the Python logging module's documentation for more info.

Instead of using the predefined 'minx_formatter' and 'minx_handler' keys as described above, you can also reset the config object's logger attribute to anything you want.

Miscellaneous Settings

Constructor & Destructor Documentation

def minx.core.config.config.__init__ (   self)

Default values for various settings.

Instantiating this class will result in a config object with default values for the various settings. Clients can then assign different values to the desired attributes to customize Minx and pass the modified config object to the wm constructor.

Member Function Documentation

def minx.core.config.config.log_level (   self,
  level 
)

Set the level of logging verbosity.

Parameters
levelThe log level from the Python logging module.

The default log level is logging.WARNING. Thus, only WARNING, ERROR, and CRITICAL messages will be printed. However, with this function, you can change the log level to either produce more or fewer messages.

Consult the Python logging documentation for more details about logging levels.

def minx.core.config.config.log_to_console (   self)

Send log messages to STDERR.

This is a convenience function that allows you to avoid dealing directly with the config.logger attribute's complicated dict-of-dict-of-dict structure. Using it, you can easily configure Minx's log messages to be printed to STDERR.

def minx.core.config.config.log_to_file (   self,
  name,
  mode = 'w' 
)

Send log messages to a file.

Parameters
nameLog file's name.
modeLog file open mode; default = 'w'.

One of the most common configurations for logging is to send log messages to a file. This function configures the config.logger attribute so that log messages will be written to the named file. By default, the log will be overwritten. However, if you use the value 'a' for the mode parameter, log messages will be appended to the file.

As described earlier, you can configure Minx's logging by directly manipulating the config.logger dict. However, since that process can be somewhat convoluted and because sending log messages to a file is a fairly common thing to do, it's easier to use this function.