mewlo.mpacks.core.eventlog.mevent module This module contains classes and functions for custom event/error handling.

We use this Event class to store data associated with an event/error/warning/etc, and to write such events out to a log file or database log.

There are some alternatives for how we might represent the data associated with an Event class.

One alternative would be to define lots of specific separate member properties for all (most) fields we may want to record. This would be the classic OOP method. The advantage is better ability to typecheck fields, less possibility of errors in specifying or missing fields, better function all error checking. A disadvantage is that there are a lot of potential fields, it may get a bit messy to have a member property for each one.

The other alternative would be to allow event fields to be open ended, specified as a dictionary. The advantage is greater flexibility in adding fields, and easier support of lots of fields. If we think we might have to support an “other” dictionary of arbitrary properties, then might be simpler to just have everything be in that dictionary. This gives us a unified way of representing fields in a dictionary.

We chose to use the second alternative. All event fields are represented in a single dictionary.

In order to support better error checking, we have a (possibly optional and turned off for performance) validation function to make sure the field values are valid.

About saving events and their fields: There are cases where we are not logging events to a target with a fixed set of columns. In such cases we don’t have to worry about arbitrary or unexpected fields, and a web application can invent it’s own field property names. However, in a more traditional target, writing to a database table, each field corresponds to a column, and most database engines will not allow us to add arbitrary field columns. So we must decide how we want to handle such cases. There are two separate issues we can consider. First, we must consider how the columns are defined/decided. And second we must decide how to handle fields which don’t have a dedicated database column. Our approach will be as follows: Database target loggers will specify a mapping from event fields to columns, a list of fields to discard, and then an optional generic text column which will serialize any other fields.

Official Fields (not all will be in every event):
type: FAILURE | ERROR | WARNING | EXCEPTION msg: Full text of the event messsage (can be arbitrarily long and contain newlines) exp: Exception object related to the event request: The MewloRequest object associated with the event (note the request object contains the response object) traceback: The traceback object associated with the event statuscode: The http status code associated with an error (we might later want to remove this and just pass request object and let logger grab statuscode from request response) loc: A dictionary containing keys [filename,lineno,function_name] of the event; support functions for adding events can grab this info automatically from callstack
mewlo.mpacks.core.eventlog.mevent.EDebug(msg, *args, **kwargs)[source]

Helper function to create debug type event

mewlo.mpacks.core.eventlog.mevent.EError(msg, *args, **kwargs)[source]

Helper function to create error type event

mewlo.mpacks.core.eventlog.mevent.EException(msg, *args, **kwargs)[source]

Helper function to create exception type event with full exception traceback info.

mewlo.mpacks.core.eventlog.mevent.EFailure(msg, *args, **kwargs)[source]

Helper function to create failure type event

mewlo.mpacks.core.eventlog.mevent.EFailureExtend(failure, msg, *args, **kwargs)[source]

Helper function to create failure type event by (possibly) extending another, or using another stringifyable object.

mewlo.mpacks.core.eventlog.mevent.EInfo(msg, *args, **kwargs)[source]

Helper function to create debug type event

mewlo.mpacks.core.eventlog.mevent.EWarning(msg, *args, **kwargs)[source]

Helper function to create warning type event

class mewlo.mpacks.core.eventlog.mevent.Event(fields=None, defaultfields=None)[source]

Bases: object

Base class for event/error class.


Return the event string as it should be formatted for saving to log file. ATTN: we probably don’t want the EVENT to decide this – rather the log target, etc.


We sometimes want to write out an event as a log message to python logger; in that case we need a logging level. Python logging levels are:

DEBUG Detailed information, typically of interest only when diagnosing problems. INFO Confirmation that things are working as expected. WARNING An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ?disk space low?). The software is still working as expected. ERROR Due to a more serious problem, the software has not been able to perform some function. CRITICAL A serious error, indicating that the program itself may be unable to continue running.
classmethod calc_traceback_text()[source]

Class function to get current stack traceback as text. Used when creating an event from an exception.

fieldmatches(fieldname, fieldval)[source]

Check if etype matches.

flag_safetycheckfields = True
getfield(fieldname, defaultval=None)[source]

Merge in new fields over existing, taking care of cases where one or both fields are None.


Merge in missing fields.


Simple accessor.

classmethod pythonlogginglevel_to_eventlevel(pythonlevel)[source]

Convert from a python logging level to our internal mewlo level.


Check to make sure this is an allowed fieldname – helps to catch coding typo errors ATTN: disable on optimization.


Check to make sure fields are allowed fieldnames – helps to catch coding typo errors ATTN: we should disable this on optimization.

setfield(fieldname, fieldval)[source]

Return nice formatted string representation of event.

class mewlo.mpacks.core.eventlog.mevent.EventList[source]

Bases: object

Event list holds multiple events and provides some helper functions for working with multiple events.


Add context value to current context as dotted string path.

add_simple(msg, fields=None)[source]

Add a simple event – either from a string msg OR an existing event, which we modify.


Just append a new event.


Shorthand to count the number of events of error type.

countfieldmatches(fieldname, fieldval)[source]

Count the number of events that have a matching fieldvalue – useful for example for counting number of events of type ERROR.


Set context value – useful when generating lots of events that all have same parent-set context.


Return a string that is a comma separated join of all events, regardless of type. Useful for quick debugging.

mewlo.mpacks.core.eventlog.mevent.SimpleEventBuilder(eventtype, msg, fields=None, obj=None, exp=None, flag_loc=False, flag_traceback=False, calldepth=0)[source]

Internal func. Helper function to create failure type event

Table Of Contents

Previous topic

mewlo.mpacks.core.eventlog package

Next topic

mewlo.mpacks.core.eventlog.mewloexception module

This Page