Logging bug in python-driver/benchmarks/base.py

17 views
Skip to first unread message

David Paulsen

unread,
Aug 12, 2015, 7:55:04 PM8/12/15
to DataStax Python Driver for Apache Cassandra User Mailing List
New to Cassandra here.  I'm wanting to exercise a Cassandra installation hosted on a storage array, starting to drive some traffic with benchmarks/sync.py, intending to try various other benchmarks scripts, settings, etc.

Long story short, I think there's a bug in benchmarks/base.py, in the parse_options() function on or around line 200 (did a git pull just now), where the line of code in question reads:
200     log.setLevel(options.log_level.upper())

If I'm understanding this properly, that's calling log.setLevel() with a string rather than say logging.INFO or logging.WARNING, and so on, per:
https://docs.python.org/2/library/logging.html#levels

Python on this particular client system (RHEL 6.5) is Python 2.6.6 (r266:84292, Sep  4 2013, 07:46:00)

Thinking I'll throw together some sort of dict to map the string:
{
"CRITICAL": logging.CRITICAL,
"ERROR": logging.ERROR,
"WARNING": logging.WARNING,
"INFO": logging.INFO,
"DEBUG": logging.DEBUG
}

cheers,
:^)
djp

Jon Ribbens

unread,
Aug 13, 2015, 7:19:58 AM8/13/15
to DataStax Python Driver for Apache Cassandra User Mailing List
On Wed, Aug 12, 2015 at 04:55:04PM -0700, David Paulsen wrote:
> Long story short, I think there's a bug in benchmarks/base.py, in the
> parse_options() function on or around line 200 (did a git pull just now),
> where the line of code in question reads:
> 200 log.setLevel(options.log_level.upper())
>
> If I'm understanding this properly, that's calling log.setLevel() with a
> string rather than say logging.INFO or logging.WARNING, and so on, per:
> https://docs.python.org/2/library/logging.html#levels

More specifically, that is only a bug because the driver claims to
support Python 2.6. On all other supported versions, you are allowed
to call setLevel() with a string (this was introduced in 2.7 and 3.2).

Adam Holmberg

unread,
Aug 13, 2015, 10:36:24 AM8/13/15
to python-dr...@lists.datastax.com
More specifically, that is only a bug because the driver claims to support Python 2.6.
+1; We strive to support 2.6-3.x in the core and tests. I would not be surprised to find anomalies like this in ancillary artifacts.

I would welcome an update if you're interested in making that work.

Regards,
Adam Holmberg 


To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-u...@lists.datastax.com.



--

David Paulsen

unread,
Aug 13, 2015, 1:20:36 PM8/13/15
to DataStax Python Driver for Apache Cassandra User Mailing List
Thanks Jon and Adam.  It's been a while since I've dropped below Py 2.7 and I had a hunch that what Jon said might be so.

FWIW, did this on my copy:
diff --git a/benchmarks/base.py b/benchmarks/base.py
index 65df528..5d82055 100644
--- a/benchmarks/base.py
+++ b/benchmarks/base.py
@@ -197,7 +197,15 @@ def parse_options():

     options.hosts = options.hosts.split(',')

-    log.setLevel(options.log_level.upper())
+    logSettings = {
+    "CRITICAL": logging.CRITICAL,
+    "ERROR": logging.ERROR,
+    "WARNING": logging.WARNING,
+    "INFO": logging.INFO,
+    "DEBUG": logging.DEBUG
+    }
+    log_level = logSettings.get(options.log_level.upper()) or logging.NOTSET
+    log.setLevel(log_level)

     if options.asyncore_only:
         options.supported_reactors = [AsyncoreConnection]


Another good option would be something along the lines of adding "NOTSET" as a dict key and:
if logSettings.get(options.log_level.upper()) is None:
    # print an error message and exit

To unsubscribe from this group and stop receiving emails from it, send an email to python-driver-user+unsub...@lists.datastax.com.



--

Reply all
Reply to author
Forward
0 new messages