-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add programatic usage example, #93
base: master
Are you sure you want to change the base?
Conversation
Good point! It looks like this example has been missing a line since forever, oops! I'm hesitant to expose the private parsing APIs eliottree uses internally for it own ends (like building the whole inventory in order to better report errors, etc.). The example should look something like this: import json, sys
from eliottree import tasks_from_iterable, render_tasks
with open('eliot.log', 'rb') as fd:
tasks = tasks_from_iterable(json.loads(line) for line in fd)
# Or `codecs.getwriter('utf-8')(sys.stdout).write` on Python 2.
render_tasks(sys.stdout.write, tasks, colorize=True)
That seems like an eliot question more than an eliottree question, all eliottree wants is an iterable of tasks to render.
The above example is suitable for streaming usage, Of course Although, looking at |
@adiroiban Maybe if you can give me an idea of what your plan for streaming is (for example, is it from a file to a web browser via websocket?) we can see if there's an example that's not super complex. |
I am new to eliot.... but I have this code https://github.com/twisted/txacme/blob/151-acme-v2/docs/client_example.py#L123 Instead of Feel free to close this PR and merge your version as a drive by. Thanks! |
I use this little snippet to render complete eliot tasks as they roll in: from eliot import add_destinations
from eliot.parse import Parser
from eliottree import render_tasks
class EliotTreeDestination:
def __init__(self, out=sys.stdout.write, **opts):
self.out = out
self.opts = opts
self._parser = Parser()
def __call__(self, message):
tasks, self._parser = self._parser.add(message)
if tasks:
render_tasks(self.out, tasks, **self.opts)
add_destinations(EliotTreeDestination(colorize=True, colorize_tree=True, human_readable=True)) |
Thanks. That looks ok. My suggestion is to make this a public/upstream API. What do you think? |
I don't understand the current example for programmatic usage from the readme.
I took a look at the cli code and ended up with this example.
yes... it uses private API
Free free to update it with the public api.
How can you programmatically stop the eliot logging and cause it to flush the log file?
An example for programatting streaming usage would be nice
This change is