Skip to content

Commit e756e92

Browse files
authored
Remove custom logging. (#1514)
This is very old and was probably mostly useful while the GCP integrations were in development. However, it interferes with the user's logging in a way that's peculiar to Kaggle, so let's remove it to make Kaggle more similar to other platforms. http://b/455836683
1 parent 7081860 commit e756e92

File tree

4 files changed

+17
-153
lines changed

4 files changed

+17
-153
lines changed

Dockerfile.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ ADD patches/kaggle_gcp.py \
164164
patches/kaggle_session.py \
165165
patches/kaggle_web_client.py \
166166
patches/kaggle_datasets.py \
167-
patches/log.py \
168167
$PACKAGE_PATH/
169168

170169
# Figure out why this is in a different place?

patches/kaggle_gcp.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import inspect
3+
import logging
34
from google.auth import credentials, environment_vars
45
from google.auth.exceptions import RefreshError
56
from google.api_core.gapic_v1.client_info import ClientInfo
@@ -8,8 +9,6 @@
89
from google.cloud.bigquery._http import Connection
910
from kaggle_secrets import GcpTarget, UserSecretsClient
1011

11-
from log import Log
12-
1312
KAGGLE_GCP_CLIENT_USER_AGENT="kaggle-gcp-client/1.0"
1413

1514
def get_integrations():
@@ -22,7 +21,7 @@ def get_integrations():
2221
target = GcpTarget[integration.upper()]
2322
kernel_integrations.add_integration(target)
2423
except KeyError as e:
25-
Log.error(f"Unknown integration target: {integration.upper()}")
24+
logging.debug(f"Unknown integration target: {integration.upper()}")
2625
return kernel_integrations
2726

2827

@@ -66,14 +65,14 @@ def refresh(self, request):
6665
elif self.target == GcpTarget.CLOUDAI:
6766
self.token, self.expiry = client._get_cloudai_access_token()
6867
except ConnectionError as e:
69-
Log.error(f"Connection error trying to refresh access token: {e}")
68+
logging.error(f"Connection error trying to refresh access token: {e}")
7069
print("There was a connection error trying to fetch the access token. "
7170
f"Please ensure internet is on in order to use the {self.target.service} Integration.")
7271
raise RefreshError('Unable to refresh access token due to connection error.') from e
7372
except Exception as e:
74-
Log.error(f"Error trying to refresh access token: {e}")
73+
logging.error(f"Error trying to refresh access token: {e}")
7574
if (not get_integrations().has_integration(self.target)):
76-
Log.error(f"No {self.target.service} integration found.")
75+
logging.error(f"No {self.target.service} integration found.")
7776
print(
7877
f"Please ensure you have selected a {self.target.service} account in the Notebook Add-ons menu.")
7978
raise RefreshError('Unable to refresh access token.') from e
@@ -102,7 +101,7 @@ def api_request(self, *args, **kwargs):
102101
msg = ("Permission denied using Kaggle's public BigQuery integration. "
103102
"Did you mean to select a BigQuery account in the Notebook Add-ons menu?")
104103
print(msg)
105-
Log.info(msg)
104+
logging.info(msg)
106105
raise e
107106

108107

@@ -156,23 +155,23 @@ def monkeypatch_bq(bq_client, *args, **kwargs):
156155
# Remove these two lines once this is resolved:
157156
# https://github.com/googleapis/google-cloud-python/issues/8108
158157
if explicit_project_id:
159-
Log.info(f"Explicit project set to {explicit_project_id}")
158+
logging.info(f"Explicit project set to {explicit_project_id}")
160159
kwargs['project'] = explicit_project_id
161160
if explicit_project_id is None and specified_credentials is None and not has_bigquery:
162161
msg = "Using Kaggle's public dataset BigQuery integration."
163-
Log.info(msg)
162+
logging.info(msg)
164163
print(msg)
165164
return PublicBigqueryClient(*args, **kwargs)
166165
else:
167166
if specified_credentials is None:
168-
Log.info("No credentials specified, using KaggleKernelCredentials.")
167+
logging.info("No credentials specified, using KaggleKernelCredentials.")
169168
kwargs['credentials'] = KaggleKernelCredentials()
170169
if (not has_bigquery):
171-
Log.info("No bigquery integration found, creating client anyways.")
170+
logging.info("No bigquery integration found, creating client anyways.")
172171
print('Please ensure you have selected a BigQuery '
173172
'account in the Notebook Add-ons menu.')
174173
if explicit_project_id is None:
175-
Log.info("No project specified while using the unmodified client.")
174+
logging.info("No project specified while using the unmodified client.")
176175
print('Please ensure you specify a project id when creating the client'
177176
' in order to use your BigQuery account.')
178177
kwargs['client_info'] = set_kaggle_user_agent(kwargs.get('client_info'))
@@ -196,20 +195,20 @@ def monkeypatch_aiplatform_init(aiplatform_klass, kaggle_kernel_credentials):
196195
def patched_init(*args, **kwargs):
197196
specified_credentials = kwargs.get('credentials')
198197
if specified_credentials is None:
199-
Log.info("No credentials specified, using KaggleKernelCredentials.")
198+
logging.info("No credentials specified, using KaggleKernelCredentials.")
200199
kwargs['credentials'] = kaggle_kernel_credentials
201200
return aiplatform_init(*args, **kwargs)
202201

203202
if (not has_been_monkeypatched(aiplatform_klass.init)):
204203
aiplatform_klass.init = patched_init
205-
Log.info("aiplatform.init patched")
204+
logging.info("aiplatform.init patched")
206205

207206
def monkeypatch_client(client_klass, kaggle_kernel_credentials):
208207
client_init = client_klass.__init__
209208
def patched_init(self, *args, **kwargs):
210209
specified_credentials = kwargs.get('credentials')
211210
if specified_credentials is None:
212-
Log.info("No credentials specified, using KaggleKernelCredentials.")
211+
logging.info("No credentials specified, using KaggleKernelCredentials.")
213212
# Some GCP services demand the billing and target project must be the same.
214213
# To avoid using default service account based credential as caller credential
215214
# user need to provide ClientOptions with quota_project_id:
@@ -227,7 +226,7 @@ def patched_init(self, *args, **kwargs):
227226

228227
if (not has_been_monkeypatched(client_klass.__init__)):
229228
client_klass.__init__ = patched_init
230-
Log.info(f"Client patched: {client_klass}")
229+
logging.info(f"Client patched: {client_klass}")
231230

232231
def set_kaggle_user_agent(client_info: ClientInfo):
233232
# Add kaggle client user agent in order to attribute usage.
@@ -360,4 +359,4 @@ def init():
360359
# google.cloud.* and kaggle_gcp. By calling init here, we guarantee
361360
# that regardless of the original import that caused google.cloud.* to be
362361
# loaded, the monkeypatching will be done.
363-
init()
362+
init()

patches/log.py

Lines changed: 0 additions & 133 deletions
This file was deleted.

patches/sitecustomize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import logging
12
import os
23

3-
from log import Log
4-
54
import sys
65
import importlib.abc
76
import importlib

0 commit comments

Comments
 (0)