microsoft / vscode-pylint

Linting support for python using the pylint library.
https://marketplace.visualstudio.com/items?itemName=ms-python.pylint
MIT License
70 stars 34 forks source link

problem with pygls logging. #568

Closed shtalinberg closed 1 month ago

shtalinberg commented 1 month ago

Hi

Diagnostic Data

Reproduction Steps:

every click in editor with .py file add lines to my project log-file like [2024-08-06 13:27:05,360] INFO 140179885633536 [pygls.protocol.json_rpc:386] Sending data: {"id": 13, "jsonrpc": "2.0", "result": null}

Extra Details

My logging settings in Django project

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'file_main': {
            'format': "[%(asctime)s] %(levelname)s %(thread)d [%(name)s:%(lineno)s] %(message)s",
        },
        'standard': {'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'},
        'standard_ip': {
            'format': '%(asctime)s %(client_ip)s [%(levelname)s] %(name)s: %(message)s'
        },
        "post_office": {
            "format": "[%(levelname)s]%(asctime)s PID %(process)d: %(message)s",
            "datefmt": "%d-%m-%Y %H:%M:%S",
        },
    },
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
        'require_debug_false': {'()': 'django.utils.log.RequireDebugFalse'},
    },
    'handlers': {
        'logfile_main': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(PROJECT_LOGS_ROOT, 'main_project.log'),
            'maxBytes': 1024 * 1024 * 20,  # 20 mb
            'formatter': 'file_main',
            'encoding': 'UTF-8',
        },
    },
    'loggers': {
        '': {
            'handlers': ['logfile_main'],
            'level': 'INFO',
            'propagate': True,
        },
    },
}

video how it is happening
https://github.com/user-attachments/assets/23500274-e908-4245-b04a-7d136de300d1

karthiknadig commented 1 month ago

@shtalinberg The log itself is coming from pygls, this extension does not specifically do any logging of its own in this manner. There is likely configuration issue with how the logging is setup. The above code does now show how this is hooked up. Are you enabling logging at the process level, i.e., at python process launch. Can you share more details on how the logging is setup?

shtalinberg commented 1 month ago

@karthiknadig

  1. If you watch the video of what I did, my project isn't even running there.
  2. this happens in all my Django projects
  3. I did not configure anything to log in to vscode
  4. as soon as I disable the pylint extension - this does not happen anymore
  5. why does it write to the log file of the project in all projects even if it isn't running??? this is the most surprising
karthiknadig commented 1 month ago

This happens because pylint loads the project to perform analysis. In this case, the pygls server we use also configures its own logging. The issue is not with the extension or the pylint server, but more with how the logging was configured (in pygls or you package). Basically, it comes down to how the filtering for the logging is set up. The issue here is that pygls, pylint and your project are all getting loaded in the same process.

There is a workaround, at least with the extension: set "pylint.path" : ["${interpreter}", "-m", "pylint"] this should isolate the two packages.

Note that this does not prevent any other packages logging to be propagated to your logs. This is one another thing to try:

    'loggers': {
        '': {
            'handlers': ['logfile_main'],
            'level': 'INFO',
            'propagate': False, # Prevent other loggers from propagating to this one
        },
    },