Created
April 5, 2011 10:10
-
-
Save eblot/605c3611622890e0d78c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From fac469a6320b7d6649f52b76ff4955c8e787d834 Mon Sep 17 00:00:00 2001 | |
From: Emmanuel Blot <eblot@neotion.com> | |
Date: Tue, 5 Apr 2011 12:10:18 +0200 | |
Subject: [PATCH] Disable do_trace method evaluation when PYUSB_DEBUG_LEVEL is not defined | |
--- | |
usb/__init__.py | 2 ++ | |
usb/_debug.py | 10 ++++++++++ | |
2 files changed, 12 insertions(+), 0 deletions(-) | |
diff --git a/usb/__init__.py b/usb/__init__.py | |
index 7d820d0..27f7c71 100644 | |
--- a/usb/__init__.py | |
+++ b/usb/__init__.py | |
@@ -47,10 +47,12 @@ __all__ = ['legacy', 'core', 'backend', 'util'] | |
def _setup_log(): | |
+ from usb import _debug | |
logger = logging.getLogger('usb') | |
debug_level = os.getenv('PYUSB_DEBUG_LEVEL') | |
if debug_level is not None: | |
+ _debug.enable_tracing(True) | |
filename = os.getenv('PYUSB_LOG_FILENAME') | |
LEVELS = {'debug': logging.DEBUG, | |
diff --git a/usb/_debug.py b/usb/_debug.py | |
index 0b3f765..13b0ced 100644 | |
--- a/usb/_debug.py | |
+++ b/usb/_debug.py | |
@@ -33,6 +33,12 @@ __all__ = ['methodtrace', 'functiontrace'] | |
import logging | |
import usb._interop as _interop | |
+_enable_tracing = False | |
+ | |
+def enable_tracing(enable): | |
+ global _enable_tracing | |
+ _enable_tracing = enable | |
+ | |
def _trace_function_call(logger, fname, *args, **named_args): | |
logger.debug( | |
# TODO: check if 'f' is a method or a free function | |
@@ -44,6 +50,8 @@ def _trace_function_call(logger, fname, *args, **named_args): | |
# decorator for methods calls tracing | |
def methodtrace(logger): | |
def decorator_logging(f): | |
+ if not _enable_tracing: | |
+ return f | |
def do_trace(*args, **named_args): | |
# this if is just a optimization to avoid unecessary string formatting | |
if logging.DEBUG >= logger.getEffectiveLevel(): | |
@@ -57,6 +65,8 @@ def methodtrace(logger): | |
# decorator for methods calls tracing | |
def functiontrace(logger): | |
def decorator_logging(f): | |
+ if not _enable_tracing: | |
+ return f | |
def do_trace(*args, **named_args): | |
# this if is just a optimization to avoid unecessary string formatting | |
if logging.DEBUG >= logger.getEffectiveLevel(): | |
-- | |
1.7.4.1+GitX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment