Ver Fonte

HUE-7447 [core] Add thread tracebacks into the logs in debug mode

Romain Rigaux há 8 anos atrás
pai
commit
91c4f81c28

+ 14 - 4
desktop/core/src/desktop/lib/thread_util.py

@@ -15,9 +15,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import logging
+import socket
 import sys
 import threading
 import traceback
+import StringIO
+
+
+LOG = logging.getLogger(__name__)
+
 
 def dump_traceback(file=sys.stderr, all_threads=True):
   """Print a thread stacktrace"""
@@ -34,8 +41,11 @@ def dump_traceback(file=sys.stderr, all_threads=True):
       name = "Current thread"
     else:
       name = "Thread"
-
-    print >> file, "%s %s %s (most recent call last):" % (name, thread.name, thread.ident)
+    
+    trace_buffer = StringIO.StringIO()
+    print >> trace_buffer, "%s: %s %s %s (most recent call last):" % (socket.gethostname(), name, thread.name, thread.ident)
     frame = sys._current_frames()[thread.ident]
-    traceback.print_stack(frame, file=file)
-    print >> file
+    traceback.print_stack(frame, file=trace_buffer)
+
+    print >> file, trace_buffer.getvalue()
+    logging.debug(trace_buffer.getvalue())

+ 1 - 1
desktop/core/src/desktop/lib/thrift_util.py

@@ -447,7 +447,7 @@ class SuperClient(object):
           # Log the duration at different levels, depending on how long
           # it took.
           logmsg = "Thrift call %s.%s returned in %dms: %s" % (
-            str(self.wrapped.__class__), attr, duration*1000, log_msg)
+            str(self.wrapped.__class__), attr, duration * 1000, log_msg)
           if duration >= WARN_LEVEL_CALL_DURATION_MS:
             logging.warn(logmsg)
           elif duration >= INFO_LEVEL_CALL_DURATION_MS: