Use logger.isEnabledFor(logging.DEBUG) instead of logger.level <= logging.DEBUG for debug guards
Mantenedores costumam responder em até 5 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 55/100
Direção de pesquisa
Comece pesquisando por logger.level <= logging.DEBUG em slack_sdk/ e, em seguida, inspecione os exemplos de Socket Mode em slack_sdk/socket_mode/, incluindo builtin/client.py e client.py. Decida se a mudança se aplica apenas ao Socket Mode ou a todas as aproximadamente 88 ocorrências; considera-se concluído quando as verificações de debug usam os níveis efetivos do logger e as ocorrências em todo o projeto são tratadas de forma consistente, mantendo os guards apenas onde evitam trabalho dispendioso.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
Throughout Socket Mode, debug logs are guarded like this:
if self.logger.level <= logging.DEBUG:
self.logger.debug(f"... {expensive_call()} ...")
The guard exists to avoid building the message string when debug is off (the f-string argument is evaluated eagerly, before debug() can no-op it). That's a valid goal — e.g. builtin/client.py calls debug_redacted_message_string(message), and client.py calls self.message_queue.qsize() inside the message.
But logger.level is the wrong check: it's only the level explicitly set on that exact logger, defaulting to NOTSET (0). These loggers are created with logging.getLogger(__name__) and setLevel() is never called on them. So with the usual logging.basicConfig(level=logging.INFO) (which configures the root logger), logger.level stays 0, 0 <= 10 is always True, and the guard passes anyway — the expensive string still gets built. The optimization silently does nothing in the most common setup.
Suggested change
Replace:
if self.logger.level <= logging.DEBUG:
with:
if self.logger.isEnabledFor(logging.DEBUG):
isEnabledFor() uses the effective level (walking up the logger hierarchy via getEffectiveLevel()), so it correctly short-circuits when logging is configured at the root/parent — which is what the guard was meant to do.
Where the guarded message is cheap (e.g. it only interpolates an already-computed value), the guard could simply be dropped instead.
Scope
Spotted in slack_sdk/socket_mode/, but the same logger.level <= logging.DEBUG idiom appears ~88 times across ~23 files in slack_sdk/ (webhook, scim, web, audit_logs, rtm, oauth, …). isEnabledFor is currently used nowhere. Worth deciding whether to fix Socket Mode only or apply the change project-wide.
- Linguagem predominante
- Python
- Estrelas
- 4k
- Forks
- 861
- Merge médio
- 3d 17h
- PRs com merge (30d)
- 11
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de slackapi/python-slack-sdk
-
auto-triage-stale needs info server-side-issue
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
slackapi/python-slack-sdk#1961 · 4 comentários ·
Mantenedores costumam responder em até 5 dias
-
auto-triage-skip discussion
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
slackapi/python-slack-sdk#1940 · 2 comentários ·
Mantenedores costumam responder em até 5 dias
-
chat_postMessage silently forwards thread_id to the API, so a threaded reply posts to the channelAbertaauto-triage-skip enhancement
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
slackapi/python-slack-sdk#1923 · 2 comentários ·
Mantenedores costumam responder em até 5 dias
-
files_upload_v2 should respect the retry handlersTalvez já em andamento @DSeaStar assumiu há 60 dias. Abertaauto-triage-skip bug python web-client
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 52/100
slackapi/python-slack-sdk#1853 · 2 comentários ·
Mantenedores costumam responder em até 5 dias
-
auto-triage-skip bug server-side-issue
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
slackapi/python-slack-sdk#1847 · 5 comentários ·
Mantenedores costumam responder em até 5 dias
Todas as issues de slackapi/python-slack-sdk
Issues semelhantes
-
[Bug]: LangGraph Store sync put bypasses namespace validationTalvez já em andamento @ktz03 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
volcengine/OpenViking#6050 ·
Mantenedores costumam responder em até 1 dia
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunkTalvez já em andamento @rodricksz4h5 assumiu hoje. Abertaarea/streaming comp/gateway P2 type/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
NousResearch/hermes-agent#138245 ·
Mantenedores costumam responder em até 1 dia
-
[oblt-aw][autodoc] Update user onboarding guide for mandatory trigger CODEOWNERS stepTalvez já em andamento @github-actions assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia
-
correction metadata
Dificuldade 2/5 Menos de uma hora Facilidade para iniciantes 68/100
acl-org/acl-anthology#10378 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
cloudtrail_multi_region_enabled_logging_management_events fails when the advanced event selector has a custom nameTalvez já em andamento @12YYCCYY16 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
prowler-cloud/prowler#13033 ·
Mantenedores costumam responder em até 1 dia