-
Notifications
You must be signed in to change notification settings - Fork 119
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
Ability to write logs from alternative languages #236
Comments
So this is something that needs to be fixed. In order to make this work we need to make modifications to the way python process is spawned. It shouldn't be that complicated, but you have to understand how it's currently working. see: https://github.com/bigcompany/hook.io/blob/master/lib/resources/hook/stderr/index.js most importantly, we need to modify https://github.com/bigcompany/hook.io/blob/master/bin/run-hook#L285 Right now it looks like all |
Thank you. So we have such ability: |
@pyhedgehog - Is better we make this integrated as part of Make nice |
Maybe That way it would be supported for all languages easily? |
( no need to make json object in code ) |
That sounds like best practice for python @pyhedgehog Can you make pull request to I think maybe it's easy to do? |
I think such changes should be installed explicitly by micro-service author. Thats what I mean by "allow someone to choose different approach". There are "Explicit is better than implicit" statement in The Zen of Python. import hookio
Hook = hookio.install_sdk(Hook) And anyone who don't want (i.e. wants only datastore), will use: import hookio
Hook = hookio.install_sdk(Hook, inject_logging=False)
val = Hook.sdk.datastore.get(Hook.params['name']) or ever: import hookio
sdk = hookio.createClient()
val = sdk.datastore.get(Hook['params']['name']) |
Node.js has You tell me Python has Sugar syntax for logs is expected platform feature. |
Felicitous remark. I will consider it. |
Default functionality of |
Don't worry about incompabitilties, python needs logs. present solution if you can, or i will try to implement a default logging class for every python service that sends to stderr |
I've prepared piece of code that can be inserted to Here is:
As you can see there are two possible logging modes:
import hookio, json, logging
logging.basicConfig()
sdk = hookio.createClient()
l1 = sdk.logs.read("pyhedgehog/hookiologging236")
l2 = map(json.loads, l1)
l3 = [logging.makeLogRecord(json.loads(o['data'])) for o in l2]
for o in reversed(l3):
logging.getLogger(o.name).handle(o) |
I've updated this gist and added This should help implementing python-pip part of hpm. |
Nice! Really excited to see Python support improve. Let's group all these changes together and try to push one update which adds logging / packages / sdk. Thank you so much for your contributions! 👍 |
I can create PR just now, but there are several points to discuss. LoggingLogging has a lot of options to select:
I think that we should export Error handlingError handling has same drawback as logging - it should have options:
Same problem hints same solution - export hook class and allow author to use it. PackagesSending package requests can be pushed only with error hook support.
SDKWhat will be state of sdk? I'm not sure that I can provide consistent support. Should I pass ownership to |
I think that for python processing |
I am deep into infrastructure refactor this week. Adding 7x more servers Python support is next on list. I want to review everything you have and will soon. Thank you so much for the contributions @pyhedgehog |
@pyhedgehog - Please feel free to triage the issues. We've got a new release coming up which is using https://github.com/stackvana/microcule for core spawning API. All python support would be done in Also, many updates to https://github.com/bigcompany/hook.io-sdk Not ready for testing yet, but will be soon. |
I've got logs working from python services locally by adding only four lines of code to the def log( entry ):
"This writes to the logs"
sys.stderr.write('{ "type": "log", "payload": { "entry": ' + json.dumps(entry) + '}}\n\n')
return This allows the following code in services: log('hello logs')
log(Hook['params']) Using this exact same pattern I have also got logs working for lua services. Unless you can think of a good reason to not do this in Python, I'm going to push forward with this pattern. The key trick here with |
I've already referenced more complete implementation of logging bridge: https://gist.github.com/pyhedgehog/99dae38d1cca86d6fb3ed0d6a4c3cab2#file-hookiologging-py-L101 Also I have several questions after last IRC session but you are offline: https://gist.github.com/pyhedgehog/3cbf3f852579ac55f325bbc3e755ffb2 |
This is very good. Thank you for your contributions. I understand much better now. My plan was to just hack a simple global Can we make the errors, logging and WSGI wrapper code go inside here: https://github.com/Stackvana/microcule/blob/master/bin/binaries/micro-python That way it would "just work" for users? Either way, I'd like to get this working soon. To answer your questions:
Yes
We'll want all of these items. item d ( SDK ) can be delivered after we ship logging and WSGI wrapper
Yes please. I'll add you to the organization. License will be MIT? |
Simple logger is now added to lua and python services in microcule This will be good to at least get some logging working ASAP. I can deploy this very soon until we can do correct pythonic fix. |
I'm digging microcule, but failed to get any log (even from javascript's |
Try running the examples manually in `master`. See the ReadMe
…On Tue, Jan 10, 2017 at 8:52 AM, PyHedgehog ***@***.***> wrote:
I'm digging microcule, but failed to get any log (even from javascript's
console.log()!) while running npm test. What should I change in
all-languages-tests.js except commenting return in the middle and
limiting languages to existing ones?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#236 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAERexorALTrYF6Da4WuusvUMeosbztGks5rQ40wgaJpZM4IgnQG>
.
|
I have preliminary changes. Is there anybody else interested in python hooks? |
python WSGI services should be online and deployed now @pyhedgehog Please take a look if you have a chance. https://hook.io/examples/python-wsgi 🎉 |
LGFM. Logging works as expected. |
In JavaScript hooks one can just use
console.log
to write entry to hook log.Is it correct, that
console.log
just writes tostderr
stream?If yes, than why it doesn't works in hooks on other languages?
I've wrote a demo:
Source: https://gist.github.com/pyhedgehog/66cdff7f2d4bcaf792b78515f4e994bf
Test: https://hook.io/pyhedgehog/pytestlog
Result: https://hook.io/pyhedgehog/pytestlog/logs
The text was updated successfully, but these errors were encountered: