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

too many logging when use black formatting with vscode - it use my django-project log-file for logging #485

Open
shtalinberg opened this issue Aug 5, 2024 · 3 comments

Comments

@shtalinberg
Copy link

Hi

this one line below generate a lot of lines in my django-project

logger.info("Sending data: %s", body)

I have a lot of lines like this
[2024-08-05 17:18:37,510] INFO 140162374721536 [pygls.protocol.json_rpc:386] Sending data: {"id": 344, "jsonrpc": "2.0", "result": []}

I think it's related to using black formatting with vscode

1 question - why it use my django-project log-file ?
2 question - how I can disable it?

My log config

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,
        },
    },
}
@karthiknadig
Copy link
Contributor

I think black formatter extension is how this issue manifested. But any project using pygls could trigger this. I suspect, something might have gone wrong with how the logger has been configured.

@alcarney
Copy link
Collaborator

alcarney commented Aug 5, 2024

1 question - why it use my django-project log-file ?

To be honest, I'm not entirely sure, it looks like your logging configuration is being applied to the Python process hosting the VSCode black formatter.

The only reasons why I can think of are

  1. You are running black and pygls as part of your django project? (Which seems unlikely)
  2. The logging configuration is somehow being applied to all Python processes started in your workspace. I assume there is more to your configuration than the LOGGING variable, where is it/how does it get used?

2 question - how I can disable it?

The best solution would be to try figure and out why the formatting process is picking up your configuration but failing that, it should at least be possible to work around it.

Looking at this part of your configuration

    'loggers': {
        '': {
            'handlers': ['logfile_main'],
            'level': 'INFO',
            'propagate': True,
        },
    },

It's very generic, have you tried only listing the loggers you are interested in e.g.?

    'loggers': {
        'my_django_project': {
            'handlers': ['logfile_main'],
            'level': 'INFO',
            'propagate': True,
        },
    },

Or adding a section to specifically disable pygls

    'loggers': {
        '': {
            'handlers': ['logfile_main'],
            'level': 'INFO',
            'propagate': True,
        },
        'pygls': {
            'level': 'ERROR',
            'handlers': []
        }
    },

(I don't have much experience with this style of logging configuration, so you may have to play around a bit to get the syntax right)

Hope that helps!

@shtalinberg
Copy link
Author

Heh ..., sorry guys. I found who does that - it's an extension Pylint - v2023.10.1 from Microsoft

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

3 participants