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

Logging module not working after import pynvim #373

Closed
chemzqm opened this issue Dec 12, 2018 · 6 comments
Closed

Logging module not working after import pynvim #373

chemzqm opened this issue Dec 12, 2018 · 6 comments

Comments

@chemzqm
Copy link

chemzqm commented Dec 12, 2018

import pynvim
import logging
logfile = '/tmp/coc-jedi.log'
level = logging.DEBUG
logging.basicConfig(filename=logfile, level=level)
logging.debug('abc')

Nothing would write to /tmp/coc-jedi.log, without import pynvim, it works as expected.

@chemzqm
Copy link
Author

chemzqm commented Dec 12, 2018

Comment out logging change in __init__.py could fix this problem:

# Required for python 2.6
#class NullHandler(logging.Handler):
#    def emit(self, record):
#        pass
#
#
#if not logging.root.handlers:
#    logging.root.addHandler(NullHandler())

@justinmk
Copy link
Member

we could skip that section for python3+

@bfredl
Copy link
Member

bfredl commented Dec 13, 2018

Should it just be moved to setup_logging()? The pynvim host should set up logging, but pynvim as a lib should leave that to the app using the library.

@Drllap
Copy link

Drllap commented Mar 1, 2023

Is there any workaround for this?

@nsbradford
Copy link

nsbradford commented Sep 8, 2023

I've found 2 workarounds for this.

First, remove the NullHandler after you've imported pynvim but before configuring your logger (the approach I'm taking with VimGPT)

from pynvim import NullHandler

# Remove the NullHandler from the root logger if it's there.
# see: https://github.com/neovim/pynvim/issues/373
for handler in logging.root.handlers:
    if isinstance(handler, NullHandler):
        logging.root.removeHandler(handler)

# now add your config
logging.basicConfig(level=args.loglevel)

Alternatively, you can setup logging before the import of pynvim:

import logging

# Set up your logging.
logging.basicConfig(level=logging.DEBUG)

# Now, import pynvim
import pynvim

@wookayin
Copy link
Member

I checked this issue and can confirm that this has fixed in pynvim 0.5.0-devel (unreleased yet). The workarounds above are valid for pynvim 0.4.3 (and would still be needed for 0.4.3).

FYI, it was fixed in ac03f5c (#492) by dropping python2 support and removing the problematic NullHandler lines.

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

No branches or pull requests

6 participants