11#
22# Copyright (c) 2020-2021 Pinecone Systems Inc. All right reserved.
33#
4- import sys
4+ import logging
55from typing import NamedTuple
66import os
77
88import certifi
9- from loguru import logger
109import requests
1110import sentry_sdk
1211import configparser
1312
1413from pinecone .core .client .exceptions import ApiKeyError
1514from pinecone .core .api_action import ActionAPI , WhoAmIResponse
16- from pinecone .core .utils .constants import CLIENT_VERSION
15+ from pinecone .core .utils import warn_deprecated
16+ from pinecone .core .utils .constants import CLIENT_VERSION , PARENT_LOGGER_NAME , DEFAULT_PARENT_LOGGER_LEVEL
1717from pinecone .core .utils .sentry import sentry_decorator as sentry
1818from pinecone .core .client .configuration import Configuration as OpenApiConfiguration
1919
2020__all__ = [
21- "Config" , "logger" , " init"
21+ "Config" , "init"
2222]
2323
24+ _logger = logging .getLogger (__name__ )
25+ _parent_logger = logging .getLogger (PARENT_LOGGER_NAME )
26+ _parent_logger .setLevel (DEFAULT_PARENT_LOGGER_LEVEL )
27+
2428
2529def _set_sentry_tags (config : dict ):
2630 sentry_sdk .set_tag ("package_version" , CLIENT_VERSION )
@@ -35,7 +39,6 @@ class ConfigBase(NamedTuple):
3539 api_key : str = ""
3640 project_name : str = ""
3741 controller_host : str = ""
38- log_level : str = ""
3942 openapi_config : OpenApiConfiguration = None
4043
4144
@@ -119,19 +122,6 @@ def reset(self, config_file=None, **kwargs):
119122 config = config ._replace (openapi_config = openapi_config )
120123 self ._config = config
121124
122- # Set log level
123- log_level = (
124- kwargs .pop ("log_level" , None )
125- or os .getenv ("PINECONE_LOG_LEVEL" )
126- or os .getenv ("PINECONE_LOGGING" )
127- or file_config .pop ("log_level" , None )
128- )
129- if log_level :
130- logger .remove ()
131- logger .add (sys .stdout , enqueue = True , level = (log_level or "ERROR" ))
132- config = config ._replace (log_level = log_level )
133- self ._config = config
134-
135125 # Sentry
136126 _set_sentry_tags ({** whoami_response ._asdict (), ** self ._config ._asdict ()})
137127
@@ -188,7 +178,15 @@ def OPENAPI_CONFIG(self):
188178
189179 @property
190180 def LOG_LEVEL (self ):
191- return self ._config .log_level
181+ """
182+ Deprecated since v2.0.2 [Will be removed in v3.0.0]; use the standard logging module logger "pinecone" instead.
183+ """
184+ warn_deprecated (
185+ description = 'LOG_LEVEL is deprecated. Use the standard logging module logger "pinecone" instead.' ,
186+ deprecated_in = '2.0.2' ,
187+ removal_in = '3.0.0'
188+ )
189+ return logging .getLevelName (logging .getLogger ('pinecone' ).level )
192190
193191
194192@sentry
@@ -201,20 +199,19 @@ def init(api_key: str = None, host: str = None, environment: str = None, project
201199 :param host: Optional. Controller host.
202200 :param environment: Optional. Deployment environment.
203201 :param project_name: Optional. Pinecone project name. Overrides the value that is otherwise looked up and used from the Pinecone backend.
204- :param log_level: Optional. Set Pinecone log level.
205202 :param openapi_config: Optional. Set OpenAPI client configuration.
206203 :param config: Optional. An INI configuration file.
204+ :param log_level: Deprecated since v2.0.2 [Will be removed in v3.0.0]; use the standard logging module to manage logger "pinecone" instead.
207205 """
208206 Config .reset (project_name = project_name , api_key = api_key , controller_host = host , environment = environment ,
209- log_level = log_level , openapi_config = openapi_config ,
210- config_file = config , ** kwargs )
211- if not bool (Config .API_KEY ):
212- logger .warning ("API key is required." )
213-
207+ openapi_config = openapi_config , config_file = config , ** kwargs )
208+ if log_level :
209+ warn_deprecated (
210+ description = 'log_level is deprecated. Use the standard logging module to manage logger "pinecone" instead.' ,
211+ deprecated_in = '2.0.2' ,
212+ removal_in = '3.0.0'
213+ )
214214
215- logger .remove ()
216- logger .add (sys .stdout , enqueue = True , level = (
217- os .getenv ("PINECONE_LOG_LEVEL" ) or os .getenv ("PINECONE_LOGGING" ) or "ERROR" ))
218215
219216Config = _CONFIG ()
220217
0 commit comments