Skip to content

Commit f39c2ed

Browse files
author
iain MacDonnell
committed
Logging adjustments
* Timestamp and log level are no longer hard-coded in log messages - rather the default logger is configured with a formatter that includes them. An application that provides its own logger may choose its own format. * Adjusted several log messages to use more appropriate levels (ERROR for errors, DEBUG for chatter).
1 parent b5d3b11 commit f39c2ed

File tree

7 files changed

+38
-23
lines changed

7 files changed

+38
-23
lines changed

CHANGELOG.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,28 @@ _____
1616
* If a delegation token is being used for authorization the HTTP header,
1717
'opc-obo-token' will be sent with the contents of the token.
1818
* Rate Limiting (cloud only):
19+
1920
* New method NoSQLHandleConfig.set_rate_limiting_enabled to enable automatic
2021
internal rate limiting based on table read and write throughput limits.
2122
* If rate limiting is enabled:
23+
2224
* NoSQLHandleConfig.set_default_rate_limiting_percentage can control how
2325
much of a table's full limits this client handle can consume
2426
(default = 100%).
2527
* Result classes now have a Result.get_rate_limit_delayed_ms method to
2628
return the amount of time an operation was delayed due to internal rate
2729
limiting.
30+
2831
* Add rate limiting example and test.
32+
2933
* RetryStats: New object allows the application to see how much time and for
3034
what reasons an operation was internally retried.
35+
3136
* For successful operations, retry stats can be retrieved using
3237
Result.get_retry_stats.
3338
* Otherwise, the original Request may have retry stats available via
3439
Request.get_retry_stats (for example, after an exception was thrown).
40+
3541
* Cloud only: New regions: ap-chiyoda-1, me-dubai-1, sa-santiago-1 and
3642
uk-cardiff-1.
3743
* Added dependency on dateutil package for flexible timestamp handling
@@ -49,15 +55,20 @@ _______
4955
* Enhance handling of TIMESTAMP types to better handle a datetime instance with
5056
an explicit timezone. By default fields of type TIMESTAMP returned by the system
5157
are represented by a "naive" (not timezone aware) datetime object in the timezone UTC.
58+
* Timestamp and log level are no longer hard-coded in log messages - rather the
59+
default logger is configured with a formatter that includes them. An application
60+
that provides its own logger may choose its own format.
61+
* Adjusted several log messages to use more appropriate levels (ERROR for errors,
62+
DEBUG for chatter).
5263

5364
Fixed
5465
_____
5566

5667
* Ensure that TableLimits is always None in TableResult on-premise.
5768
* Fixed synchronization problem in SignatureProvider.
5869
* Fixed a problem where the cloud service might succeed when dropping a table
59-
that does not exist without using "drop table if exists" when it should throw
60-
TableNotFoundException
70+
that does not exist without using "drop table if exists" when it should throw
71+
TableNotFoundException
6172

6273
Removed
6374
_______
@@ -85,6 +96,7 @@ _____
8596
CA_MONTREAL_1, EU_AMSTERDAM_1, ME_JEDDAH_1.
8697
* Cloud only. Added support for authenticating via Resource Principal. This can
8798
be used in Oracle Cloud Functions to access NoSQL cloud service:
99+
88100
* Added a new method SignatureProvider.create_with_resource_principal.
89101
* Added a new method SignatureProvider.get_resource_principal_claim to
90102
retrieve resource principal metadata with ResourcePrincipalClaimKeys such as

src/borneo/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ def __init__(self, config, logger):
7575
# StoreAccessTokenProvider means onprem
7676
if (config.get_rate_limiting_enabled() and
7777
not isinstance(self._auth_provider, StoreAccessTokenProvider)):
78-
self._logutils.log_info(
79-
'Starting client with rate limiting enabled.')
78+
self._logutils.log_debug(
79+
'Starting client with rate limiting enabled')
8080
self._rate_limiter_map = RateLimiterMap()
8181
self._table_limit_update_map = dict()
8282
self._threadpool = pool.ThreadPool(1)
8383
else:
84-
self._logutils.log_info('Starting client with no rate limiting.')
84+
self._logutils.log_debug('Starting client with no rate limiting')
8585
self._rate_limiter_map = None
8686
self._table_limit_update_map = None
8787
self._threadpool = None
@@ -242,7 +242,7 @@ def set_ratelimiter_duration_seconds(self, duration_seconds):
242242

243243
def shut_down(self):
244244
# Shutdown the client.
245-
self._logutils.log_info('Shutting down driver http client')
245+
self._logutils.log_debug('Shutting down driver http client')
246246
if self._shut_down:
247247
return
248248
self._shut_down = True
@@ -369,24 +369,24 @@ def _update_table_limiters(self, table_name):
369369
req = GetTableRequest().set_table_name(table_name).set_timeout(1000)
370370
res = None
371371
try:
372-
self._logutils.log_info(
372+
self._logutils.log_debug(
373373
'Starting GetTableRequest for table "' + table_name + '"')
374374
res = self.execute(req)
375375
except Exception as e:
376-
self._logutils.log_info(
376+
self._logutils.log_error(
377377
'GetTableRequest for table "' + table_name +
378378
'" returned exception: ' + str(e))
379379
if res is None:
380380
# table doesn't exist? other error?
381-
self._logutils.log_info(
381+
self._logutils.log_error(
382382
'GetTableRequest for table "' + table_name + '" returned None')
383383
then = self._table_limit_update_map.get(table_name)
384384
if then is not None:
385385
# Allow retry after 100ms.
386386
self._table_limit_update_map[table_name] = (
387387
int(round(time() * 1000000000)) + 100000000)
388388
return
389-
self._logutils.log_info(
389+
self._logutils.log_debug(
390390
'GetTableRequest completed for table "' + table_name + '"')
391391
# Update/add rate limiters for table.
392392
if self.update_rate_limiters(table_name, res.get_table_limits()):

src/borneo/common.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,23 +530,23 @@ def __init__(self, logger=None):
530530

531531
def log_critical(self, msg):
532532
if self._logger is not None:
533-
self._logger.critical(ctime() + '[CRITICAL]' + msg)
533+
self._logger.critical(msg)
534534

535535
def log_error(self, msg):
536536
if self._logger is not None:
537-
self._logger.error(ctime() + '[ERROR]' + msg)
537+
self._logger.error(msg)
538538

539539
def log_warning(self, msg):
540540
if self._logger is not None:
541-
self._logger.warning(ctime() + '[WARNING]' + msg)
541+
self._logger.warning(msg)
542542

543543
def log_info(self, msg):
544544
if self._logger is not None:
545-
self._logger.info(ctime() + '[INFO]' + msg)
545+
self._logger.info(msg)
546546

547547
def log_debug(self, msg):
548548
if self._logger is not None:
549-
self._logger.debug(ctime() + '[DEBUG]' + msg)
549+
self._logger.debug(msg)
550550

551551
def is_enabled_for(self, level):
552552
return self._logger is not None and self._logger.isEnabledFor(level)

src/borneo/driver.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77

88
from json import loads
9-
from logging import FileHandler, WARNING, getLogger
9+
from logging import FileHandler, Formatter, WARNING, getLogger
1010
from os import mkdir, path
1111
from ssl import SSLContext, SSLError, create_default_context
1212
from sys import argv
@@ -671,7 +671,10 @@ def _get_logger(self, config):
671671
log_dir = path.join(path.abspath(path.dirname(argv[0])), 'logs')
672672
if not path.exists(log_dir):
673673
mkdir(log_dir)
674-
logger.addHandler(FileHandler(path.join(log_dir, 'driver.log')))
674+
handler = FileHandler(path.join(log_dir, 'driver.log'))
675+
formatter = Formatter('%(asctime)s [%(levelname)s] %(message)s')
676+
handler.setFormatter(formatter)
677+
logger.addHandler(handler)
675678
else:
676679
logger = config.get_logger()
677680
return logger

src/borneo/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def _do_request(self, method, uri, headers, payload, timeout_ms):
319319
self._request.increment_retries()
320320
exception = ae
321321
continue
322-
self._logutils.log_info(
322+
self._logutils.log_error(
323323
'Unexpected authentication exception: ' + str(ae))
324324
raise NoSQLException('Unexpected exception: ' + str(ae), ae)
325325
except SecurityInfoNotReadyException as se:
@@ -460,7 +460,7 @@ def _handle_retry(self, re, request):
460460
def _log_retried(self, num_retried, exception):
461461
msg = ('Client, doing retry: ' + str(num_retried) +
462462
('' if exception is None else ', exception: ' + str(exception)))
463-
self._logutils.log_info(msg)
463+
self._logutils.log_debug(msg)
464464

465465
@synchronized
466466
def _next_request_id(self):

src/borneo/iam/iam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _refresh_task(self):
398398
# Ignore the failure of refresh. The driver would try to generate
399399
# signature in the next request if signature is not available, the
400400
# failure would be reported at that moment.
401-
self._logutils.log_warning(
401+
self._logutils.log_debug(
402402
'Unable to refresh cached request signature, ' + str(e))
403403
self._timer.cancel()
404404
self._timer = None

src/borneo/kv/kv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ def close(self):
155155
response = self._send_request(
156156
self._auth_string, StoreAccessTokenProvider._LOGOUT_SERVICE)
157157
if response.get_status_code() != codes.ok:
158-
self._logutils.log_info(
158+
self._logutils.log_error(
159159
'Failed to logout user ' + self._user_name + ': ' +
160160
response.get_content())
161161
except Exception as e:
162-
self._logutils.log_info(
162+
self._logutils.log_error(
163163
'Failed to logout user ' + self._user_name + ': ' + str(e))
164164

165165
# Clean up.
@@ -301,7 +301,7 @@ def _refresh_task(self):
301301
StoreAccessTokenProvider._BEARER_PREFIX + token)
302302
self._schedule_refresh()
303303
except Exception as e:
304-
self._logutils.log_info('Failed to renew login token: ' + str(e))
304+
self._logutils.log_error('Failed to renew login token: ' + str(e))
305305
if self._timer is not None:
306306
self._timer.cancel()
307307
self._timer = None

0 commit comments

Comments
 (0)