ranaroussi / yfinance

Download market data from Yahoo! Finance's API

Home Page:https://aroussi.com/post/python-yahoo-finance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logging is disabled app-wide during fetching in quote.py

Rogach opened this issue · comments

Describe bug

Logging is disabled in the entire application while data fetching is happening in quote.py.

Here's the code responsible: https://github.com/ranaroussi/yfinance/blob/main/yfinance/scrapers/quote.py#L186
This change was introduced in 4e7b209, "Logging: improve appearance, fix propagation"

Perhaps it is possible to silence logging output only for certain loggers instead of all loggers at once?

Simple code that reproduces your problem

import logging
logging.basicConfig(level=logging.WARN)
logging.getLogger("modules").setLevel(logging.INFO)

import yfinance
def load_data():
    yfinance.Ticker("^HSI").fast_info.last_price
from threading import Thread
Thread(target=load_data, args=[], daemon=True).start()

logger = logging.getLogger("modules.Test")
logger.warning("TEST")

print("done")

Exprected output:

WARNING:modules.Test:TEST
done

Actual output:

done

Debug log

done

Bad data proof

No response

yfinance version

main branch, commit f563e51

Python version

3.11.6

Operating system

No response

I remember wanting to silence everything during history calls in fast_info, particularly requests module. But I forget why. Given fast_info seems stable now, probably OK to revert.

I've tested without logging.disable, and the logs look okay - all at DEBUG level and mostly from yfinance itself.

Should I make a PR?

DEBUG    Entering history()
DEBUG:yfinance:Entering history()
DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "_kv" ("key" VARCHAR(255) NOT NULL PRIMARY KEY, "value" VARCHAR(255)) WITHOUT ROWID', [])
DEBUG:peewee:('SELECT "t1"."key", "t1"."value" FROM "_kv" AS "t1" WHERE ("t1"."key" = ?) LIMIT ? OFFSET ?', ['^HSI', 1, 0])
DEBUG     ^HSI: Yahoo GET parameters: {'range': '380d', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG:yfinance: ^HSI: Yahoo GET parameters: {'range': '380d', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG     Entering get()
DEBUG:yfinance: Entering get()
DEBUG      url=https://query2.finance.yahoo.com/v8/finance/chart/^HSI
DEBUG:yfinance:  url=https://query2.finance.yahoo.com/v8/finance/chart/^HSI
DEBUG      params={'range': '380d', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG:yfinance:  params={'range': '380d', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG      Entering _get_cookie_and_crumb()
DEBUG:yfinance:  Entering _get_cookie_and_crumb()
DEBUG       cookie_mode = 'basic'
DEBUG:yfinance:   cookie_mode = 'basic'
DEBUG       Entering _get_cookie_and_crumb_basic()
DEBUG:yfinance:   Entering _get_cookie_and_crumb_basic()
DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "_cookieschema" ("strategy" VARCHAR(255) NOT NULL PRIMARY KEY, "fetch_date" DATETIME NOT NULL, "cookie_bytes" BLOB NOT NULL) WITHOUT ROWID', [])
DEBUG:peewee:('SELECT "t1"."strategy", "t1"."fetch_date", "t1"."cookie_bytes" FROM "_cookieschema" AS "t1" WHERE ("t1"."strategy" = ?) LIMIT ? OFFSET ?', ['basic', 1, 0])
DEBUG        loaded persistent cookie
DEBUG:yfinance:    loaded persistent cookie
DEBUG        reusing cookie
DEBUG:yfinance:    reusing cookie
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): query1.finance.yahoo.com:443
DEBUG:urllib3.connectionpool:https://query1.finance.yahoo.com:443 "GET /v1/test/getcrumb HTTP/1.1" 200 None
DEBUG        crumb = '3Pb9PwERTE9'
DEBUG:yfinance:    crumb = '3Pb9PwERTE9'
DEBUG       Exiting _get_cookie_and_crumb_basic()
DEBUG:yfinance:   Exiting _get_cookie_and_crumb_basic()
DEBUG      Exiting _get_cookie_and_crumb()
DEBUG:yfinance:  Exiting _get_cookie_and_crumb()
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): query2.finance.yahoo.com:443
DEBUG:urllib3.connectionpool:https://query2.finance.yahoo.com:443 "GET /v8/finance/chart/%5EHSI?range=380d&interval=1d&includePrePost=False&events=div%2Csplits%2CcapitalGains&crumb=3Pb9PwERTE9 HTTP/1.1" 200 None
DEBUG      response code=200
DEBUG:yfinance:  response code=200
DEBUG     Exiting get()
DEBUG:yfinance: Exiting get()
DEBUG     ^HSI: yfinance received OHLC data: 2022-07-04 01:30:00 -> 2024-01-16 03:30:56
DEBUG:yfinance: ^HSI: yfinance received OHLC data: 2022-07-04 01:30:00 -> 2024-01-16 03:30:56
DEBUG     ^HSI: OHLC after cleaning: 2022-07-04 09:30:00+08:00 -> 2024-01-16 11:30:56+08:00
DEBUG:yfinance: ^HSI: OHLC after cleaning: 2022-07-04 09:30:00+08:00 -> 2024-01-16 11:30:56+08:00
DEBUG     ^HSI: OHLC after combining events: 2022-07-04 00:00:00+08:00 -> 2024-01-16 00:00:00+08:00
DEBUG:yfinance: ^HSI: OHLC after combining events: 2022-07-04 00:00:00+08:00 -> 2024-01-16 00:00:00+08:00
DEBUG     ^HSI: yfinance returning OHLC: 2022-07-04 00:00:00+08:00 -> 2024-01-16 00:00:00+08:00
DEBUG:yfinance: ^HSI: yfinance returning OHLC: 2022-07-04 00:00:00+08:00 -> 2024-01-16 00:00:00+08:00
DEBUG    Exiting history()
DEBUG:yfinance:Exiting history()

Can do