Skip to content

Commit

Permalink
Records no longer conflate their attributes with data_map contents
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed May 14, 2016
1 parent ee7d35d commit a9787f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
42 changes: 5 additions & 37 deletions lithoxyl/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,52 +241,20 @@ def __exit__(self, exc_type, exc_val, exc_tb):
return

def __getitem__(self, key):
try:
return getattr(self, key)
except AttributeError:
return self.data_map[key]
return self.data_map[key]

def __setitem__(self, key, value):
if hasattr(self, key):
setattr(self, key, value)
else:
self.data_map[key] = value
self.data_map[key] = value

def get_elapsed_time(self):
"""Simply get the amount of time that has passed since the record was
created or begin was called. This method has no side effects.
"""Simply get the amount of time that has passed since begin was
called on this record, or 0.0 if it has not begun. This method
has no side effects.
"""
if self.begin_event:
return time.time() - self.begin_event.etime
return 0.0

'''
@property
def status_char(self):
"""A single-character representation of the status of the Record. See
the ``status_chr`` field in the
:class:`~lithoxyl.formatter.Formatter` field documentation for
more details.
"""
ret = '_'
try:
if self._is_trans:
if self.end_time:
ret = self.status[:1].upper()
else:
ret = 'b'
else:
ret = self.status[:1].lower()
except Exception:
pass
return ret
@property
def warn_char(self):
"``'W'`` if the Record has warnings, ``' '`` otherwise."
return 'W' if self.warnings else ' '
'''


# TODO: optimization strategy. if event creation starts to register on
# profiling, convert events to fixed-length tuples with empty
Expand Down
6 changes: 3 additions & 3 deletions lithoxyl/sensible.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def __init__(self, format_str, **kwargs):
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.raw_format_str)

def format(self, record, *args, **kwargs):
def format(self, event, *args, **kwargs):
"""Render text, based on the format-string template used to construct
the object, plus values from the following sources:
Expand All @@ -279,7 +279,7 @@ def format(self, record, *args, **kwargs):
"""
ret = ''
kw_vals = GetterDict(record, self._getter_map)
kw_vals = GetterDict(event, self._getter_map)
kw_vals.update(kwargs)
q_map, d_map = self.quoter_map, self.default_map
for t in self.tokens:
Expand Down Expand Up @@ -435,7 +435,7 @@ def duration_auto(event):
_SF('record_id', 'd', lambda e: e.record_id),
_SF('status_str', 's', lambda e: e.status, quote=False),
_SF('status_char', 's', lambda e: e.status_char, quote=False),
_SF('warn_char', 's', lambda e: e.warn_char, quote=False),
_SF('warn_char', 's', lambda e: e.warn_char, quote=False), # TODO
_SF('level_name', 's', lambda e: e.level_name, quote=False),
_SF('data_map', 's', lambda e: json.dumps(e.record.data_map, sort_keys=True), quote=False),
_SF('level_name_upper', 's', lambda e: e.level_name.upper(), quote=False),
Expand Down

0 comments on commit a9787f1

Please sign in to comment.