Beispiel #1
0
def display_tasks(tasks, color, colorize_tree, ascii, theme_name,
                  ignored_fields, field_limit, human_readable, utc_timestamps,
                  theme_overrides):
    """
    Render Eliot tasks, apply any command-line-specified behaviour and render
    the task trees to stdout.
    """
    if color == 'auto':
        colorize = sys.stdout.isatty()
    else:
        colorize = color == 'always'

    setup_platform(colorize=colorize)
    write = text_writer(sys.stdout).write
    write_err = text_writer(sys.stderr).write
    if theme_name == 'auto':
        dark_background = is_dark_terminal_background(default=True)
    else:
        dark_background = theme_name == 'dark'
    theme = apply_theme_overrides(
        get_theme(dark_background=dark_background,
                  colored=colored if colorize else None), theme_overrides)

    render_tasks(write=write,
                 write_err=write_err,
                 tasks=tasks,
                 ignored_fields=set(ignored_fields) or None,
                 field_limit=field_limit,
                 human_readable=human_readable,
                 colorize_tree=colorize and colorize_tree,
                 ascii=ascii,
                 utc_timestamps=utc_timestamps,
                 theme=theme)
Beispiel #2
0
def render_stdout(message):
    """Ref:
       http://stackoverflow.com/questions/42936027/how-to-generate-eliot-tasks-for-eliottree-render-tasks
    """
    eliottree.render_tasks(codecs.getwriter('utf-8')(sys.stdout).write,
                           eliottree.tasks_from_iterable([message]),
                           colorize=True,
                           human_readable=True)
Beispiel #3
0
 def render_tasks(self, iterable, **kw):
     fd = StringIO()
     err = StringIO(u'')
     tasks = tasks_from_iterable(iterable)
     render_tasks(write=fd.write, write_err=err.write, tasks=tasks, **kw)
     if err.tell():
         return fd.getvalue(), err.getvalue()
     return fd.getvalue()
Beispiel #4
0
 def test_multiline_field(self):
     """
     When no field limit is specified for task values, multiple lines are
     output for multiline tasks.
     """
     fd = StringIO()
     tasks = tasks_from_iterable([multiline_action_task])
     render_tasks(write=fd.write, tasks=tasks)
     self.assertThat(
         fd.getvalue(),
         ExactlyEquals(u'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4\n'
                       u'\u2514\u2500\u2500 app:action/1 \u21d2 started '
                       u'1425356800\n'
                       u'    \u2514\u2500\u2500 message: this is a\u23ce\n'
                       u'        many line message\n\n'))
Beispiel #5
0
def _eliottree(logs):
    """
    Render some Eliot log events into a tree-like string.

    :param list[dict] logs: The Eliot log events to render.  These should be
        dicts like those passed to an Eliot destination.

    :return unicode: The rendered string.
    """
    tasks = tasks_from_iterable(logs)

    out = StringIO()
    render_tasks(
        write=out.write,
        tasks=tasks,
        field_limit=0,
    )
    return out.getvalue()
Beispiel #6
0
def display_tasks(tasks, color, ignored_fields, field_limit, human_readable):
    """
    Render Eliot tasks, apply any command-line-specified behaviour and render
    the task trees to stdout.
    """
    write = text_writer(sys.stdout).write
    write_err = text_writer(sys.stderr).write
    if color == 'auto':
        colorize = sys.stdout.isatty()
    else:
        colorize = color == 'always'
    render_tasks(write=write,
                 write_err=write_err,
                 tasks=tasks,
                 ignored_fields=set(ignored_fields) or None,
                 field_limit=field_limit,
                 human_readable=human_readable,
                 colorize=colorize)
Beispiel #7
0
import requests
from eliot import start_action, add_destinations, log_call
from eliottree import render_tasks, tasks_from_iterable

messages = []


def collect_messages(message):
    messages.append(message)


add_destinations(collect_messages)


@log_call
def get_some_data(url):
    requests.get(url)


try:
    with start_action(action_type='SomeOuterAction', x=123) as action:
        action.log(message_type='my_dummy_message',
                   text='something is about to happen')
        url = 'http://4ut23y74283ty872y3t47823t.com/'
        with start_action(action_type='SomeInnerAction', url=url):
            get_some_data(url)
except:
    render_tasks(sys.stdout.write,
                 tasks_from_iterable(messages),
                 colorize=True)
Beispiel #8
0
    def __call__(self, message):
        tasks, self._parser = self._parser.add(message)

        if tasks:
            render_tasks(self.out, tasks, **self.opts)