コード例 #1
0
ファイル: _render.py プロジェクト: cegfdb/eliottree
def _default_value_formatter(
    human_readable,
    field_limit,
    utc_timestamps=True,
    encoding='utf-8',
):
    """
    Create a value formatter based on several user-specified options.
    """
    fields = {}
    if human_readable:
        fields = {
            eliot_ns(u'timestamp'):
            format.timestamp(include_microsecond=False,
                             utc_timestamps=utc_timestamps),
            eliot_ns(u'duration'):
            format.duration(),
        }
    return compose(
        # We want tree-format to handle newlines.
        partial(format.escape_control_characters, overrides={0x0a: u'\n'}),
        partial(format.truncate_value, field_limit)
        if field_limit else identity,
        format.some(format.fields(fields), format.text(),
                    format.binary(encoding), format.anything(encoding)))
コード例 #2
0
ファイル: test_render.py プロジェクト: cegfdb/eliottree
 def test_timestamp_field(self):
     """
     Format Eliot ``timestamp`` fields as human-readable if the feature was
     requested.
     """
     format_value = _default_value_formatter(human_readable=True,
                                             field_limit=0)
     # datetime(2015, 6, 6, 22, 57, 12)
     now = 1433631432
     self.assertThat(format_value(now, eliot_ns(u'timestamp')),
                     ExactlyEquals(u'2015-06-06 22:57:12Z'))
     self.assertThat(format_value(str(now), eliot_ns(u'timestamp')),
                     ExactlyEquals(u'2015-06-06 22:57:12Z'))
コード例 #3
0
ファイル: _render.py プロジェクト: adiroiban/eliottree
def message_name(theme, format_value, message, end_message=None):
    """
    Derive the name for a message.

    If the message is an action type then the ``action_type`` field is used in
    conjunction with ``task_level`` and ``action_status``. If the message is a
    message type then the ``message_type`` and ``task_level`` fields are used,
    otherwise no name will be derived.
    """
    if message is not None:
        timestamp = theme.timestamp(
            format_value(
                message.timestamp, field_name=eliot_ns('timestamp')))
        if u'action_type' in message.contents:
            action_type = format.escape_control_characters(
                message.contents.action_type)
            duration = u''
            if end_message:
                duration_seconds = end_message.timestamp - message.timestamp
                duration = u' {} {}'.format(
                    HOURGLASS,
                    theme.duration(
                        format_value(
                            duration_seconds,
                            field_name=eliot_ns('duration'))))
                action_status = end_message.contents.action_status
            else:
                action_status = message.contents.action_status
            status_color = identity
            if action_status == u'succeeded':
                status_color = theme.status_success
            elif action_status == u'failed':
                status_color = theme.status_failure
            return u'{}{} {} {} {}{}'.format(
                theme.parent(action_type),
                theme.task_level(message.task_level.to_string()),
                RIGHT_DOUBLE_ARROW,
                status_color(message.contents.action_status),
                timestamp,
                duration)
        elif u'message_type' in message.contents:
            message_type = format.escape_control_characters(
                message.contents.message_type)
            return u'{}{} {}'.format(
                theme.parent(message_type),
                theme.task_level(message.task_level.to_string()),
                timestamp)
    return u'<unnamed>'
コード例 #4
0
ファイル: render.py プロジェクト: x0zzz/eliottree
 def items_children(items):
     for key, value in sorted(items):
         if key not in ignored_task_keys:
             if key == u'timestamp':
                 key = eliot_ns(key)
             if isinstance(value, dict):
                 yield key, value
             else:
                 yield key, format_value(value, key)
コード例 #5
0
ファイル: render.py プロジェクト: x0zzz/eliottree
 def get_children(task):
     if isinstance(task, text_type):
         return
     elif isinstance(task, tuple):
         if isinstance(task[1], dict):
             for child in items_children(task[1].items()):
                 yield child
         elif isinstance(task[1], text_type):
             # The value of Unicode values is incorporated into the name.
             return
         else:
             yield task[1]
         return
     else:
         for child in items_children(task.task.items()):
             if child[0] == u'timestamp':
                 yield eliot_ns(child[0]), child[1]
             else:
                 yield child
         for child in task.children():
             yield child