1
1
#
2
2
# Copyright (c) 2020-2021 Pinecone Systems Inc. All right reserved.
3
3
#
4
- import sys
4
+ import logging
5
5
from typing import NamedTuple
6
6
import os
7
7
8
8
import certifi
9
- from loguru import logger
10
9
import requests
11
10
import sentry_sdk
12
11
import configparser
13
12
14
13
from pinecone .core .client .exceptions import ApiKeyError
15
14
from 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
17
17
from pinecone .core .utils .sentry import sentry_decorator as sentry
18
18
from pinecone .core .client .configuration import Configuration as OpenApiConfiguration
19
19
20
20
__all__ = [
21
- "Config" , "logger" , " init"
21
+ "Config" , "init"
22
22
]
23
23
24
+ _logger = logging .getLogger (__name__ )
25
+ _parent_logger = logging .getLogger (PARENT_LOGGER_NAME )
26
+ _parent_logger .setLevel (DEFAULT_PARENT_LOGGER_LEVEL )
27
+
24
28
25
29
def _set_sentry_tags (config : dict ):
26
30
sentry_sdk .set_tag ("package_version" , CLIENT_VERSION )
@@ -35,7 +39,6 @@ class ConfigBase(NamedTuple):
35
39
api_key : str = ""
36
40
project_name : str = ""
37
41
controller_host : str = ""
38
- log_level : str = ""
39
42
openapi_config : OpenApiConfiguration = None
40
43
41
44
@@ -119,19 +122,6 @@ def reset(self, config_file=None, **kwargs):
119
122
config = config ._replace (openapi_config = openapi_config )
120
123
self ._config = config
121
124
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
-
135
125
# Sentry
136
126
_set_sentry_tags ({** whoami_response ._asdict (), ** self ._config ._asdict ()})
137
127
@@ -188,7 +178,15 @@ def OPENAPI_CONFIG(self):
188
178
189
179
@property
190
180
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 )
192
190
193
191
194
192
@sentry
@@ -201,20 +199,19 @@ def init(api_key: str = None, host: str = None, environment: str = None, project
201
199
:param host: Optional. Controller host.
202
200
:param environment: Optional. Deployment environment.
203
201
: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.
205
202
:param openapi_config: Optional. Set OpenAPI client configuration.
206
203
: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.
207
205
"""
208
206
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
+ )
214
214
215
- logger .remove ()
216
- logger .add (sys .stdout , enqueue = True , level = (
217
- os .getenv ("PINECONE_LOG_LEVEL" ) or os .getenv ("PINECONE_LOGGING" ) or "ERROR" ))
218
215
219
216
Config = _CONFIG ()
220
217
0 commit comments