Skip to content
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

[Question] Is there a way to make all the logs go to one file that I designate? #523

Closed
syspic opened this issue Jan 28, 2020 · 5 comments
Closed
Labels

Comments

@syspic
Copy link

syspic commented Jan 28, 2020

Question in title. I essentially want to log all the on_.... commands, mostly the on_message , to a file. However I see the way to do this has changed. It is no longer making a subclass of Client so I will have to re learn this :'(

@madsmtm
Copy link
Member

madsmtm commented Jan 28, 2020

Hmm, the new version shouldn't be released yet, so it shouldn't be a problem; just use the version on PyPI / the v1 branch; however, I'll make an issue soon asking for feedback on how the API should work in the future, so when that comes, I'll link to this issue, thanks!

@madsmtm
Copy link
Member

madsmtm commented Jan 28, 2020

Oh, and regarding your specific question, see the examples for how I've currently designed the listening system; under that design (which will change), you would do:

import fbchat
session = fbchat.Session.login(...)
listener = fbchat.Listener.connect(session, True, True)
for event in listener.listen():
    if isinstance(event, fbchat.MessageEvent):
        with open('file.log', 'a') as f:
            f.write(event.message.text)

@syspic
Copy link
Author

syspic commented Jan 29, 2020

Thank you so much for the response! I've notices you get back the people super quickly and I appreciate that

Oh ok, I see. I was looking at master by accident

As for the listener in v2, is that where all the on.. methods will go now?

@madsmtm
Copy link
Member

madsmtm commented Jan 29, 2020

Yup, that's where I'll move it. Ideally, I'd like the following to work:

import fbchat
session = fbchat.Session.login(...)
listener = fbchat.Listener(session, True, True)

@listener.register
def on_message(message: fbchat.Message):
    with open('file.log', 'a') as f:
        f.write(message.text)

listener.run()

But I'm not quite there yet.

I'll close this issue for now though, if you don't mind 😉

@madsmtm madsmtm closed this as completed Jan 29, 2020
@madsmtm
Copy link
Member

madsmtm commented Feb 5, 2020

I've made the issue asking for feedback, #526, kindly submit your thoughts! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants