Revision: 9a9580289f30
Author:   Mikko Korpela <[email protected]>
Date:     Wed Jan 11 06:11:20 2012
Log: Include logged messages from Timeout thread when logging through logging API.

Update issue 985
Status: Done
Owner: mikko.korpela
Cc: pekka.klarck
Labels: Priority-Medium
http://code.google.com/p/robotframework/source/detail?r=9a9580289f30

Modified:
 /atest/robot/test_libraries/logging_with_logging.txt
 /atest/testdata/test_libraries/LibUsingPyLogging.py
 /atest/testdata/test_libraries/logging_with_logging.txt
 /src/robot/api/logger.py
 /src/robot/running/timeouts/__init__.py
 /src/robot/running/timeouts/stoppablethread.py
 /src/robot/running/timeouts/timeoutthread.py

=======================================
--- /atest/robot/test_libraries/logging_with_logging.txt Fri Nov 11 05:57:18 2011 +++ /atest/robot/test_libraries/logging_with_logging.txt Wed Jan 11 06:11:20 2012
@@ -49,3 +49,8 @@
     Check log message  ${msg1}  First message
     Check log message  ${msg2}  Second message 0.1 sec later
     Should be true  '${msg1.timestamp}' < '${msg2.timestamp}'
+
+Logging when timeout is in use
+    ${tc} =  Check test case  ${TEST NAME}
+ Check log message ${tc.kws[0].msgs[0]} Test timeout 5 seconds active. * seconds left. DEBUG pattern=yep
+    Check log message  ${tc.kws[0].msgs[1]}  something
=======================================
--- /atest/testdata/test_libraries/LibUsingPyLogging.py Fri Nov 11 05:57:18 2011 +++ /atest/testdata/test_libraries/LibUsingPyLogging.py Wed Jan 11 06:11:20 2012
@@ -57,3 +57,6 @@
     logging.info('First message')
     time.sleep(0.1)
     logging.info('Second message 0.1 sec later')
+
+def log_something():
+    logging.info('something')
=======================================
--- /atest/testdata/test_libraries/logging_with_logging.txt Fri Nov 11 05:57:18 2011 +++ /atest/testdata/test_libraries/logging_with_logging.txt Wed Jan 11 06:11:20 2012
@@ -29,3 +29,7 @@

 Timestamps are accurate
     Log messages different time
+
+Logging when timeout is in use
+    [Timeout]  5 seconds
+    Log something
=======================================
--- /src/robot/api/logger.py    Tue Sep 13 12:55:04 2011
+++ /src/robot/api/logger.py    Wed Jan 11 06:11:20 2012
@@ -55,6 +55,10 @@
 import threading

 from robot.output import LOGGER, Message
+from robot.running.timeouts import timeoutthread
+
+
+LOGGING_THREADS = ('MainThread', timeoutthread.TIMEOUT_THREAD_NAME)


 def write(msg, level, html=False):
@@ -64,7 +68,7 @@
     of using this method, it is generally better to use the level
     specific methods such as `info` and `debug`.
     """
-    if threading.currentThread().getName() == 'MainThread':
+    if threading.currentThread().getName() in LOGGING_THREADS:
         LOGGER.log_message(Message(msg, level, html))

 def trace(msg, html=False):
=======================================
--- /src/robot/running/timeouts/__init__.py     Wed Dec 14 06:14:08 2011
+++ /src/robot/running/timeouts/__init__.py     Wed Jan 11 06:11:20 2012
@@ -31,7 +31,6 @@
 from robot import utils
 from robot.errors import TimeoutError, DataError, FrameworkError

-
 class _Timeout(object):

     def __init__(self, timeout=None, message='', variables=None):
=======================================
--- /src/robot/running/timeouts/stoppablethread.py      Wed Dec 14 01:32:15 2011
+++ /src/robot/running/timeouts/stoppablethread.py      Wed Jan 11 06:11:20 2012
@@ -28,8 +28,8 @@
     in Python because in Jython we can use java.lang.Thread.
     """

-    def __init__(self, runner):
-        threading.Thread.__init__(self, target=runner)
+    def __init__(self, runner, name=None):
+        threading.Thread.__init__(self, target=runner, name=name)
         self._stopped = False

     def start(self):
=======================================
--- /src/robot/running/timeouts/timeoutthread.py        Wed Dec 14 06:14:08 2011
+++ /src/robot/running/timeouts/timeoutthread.py        Wed Jan 11 06:11:20 2012
@@ -23,6 +23,7 @@
     from stoppablethread import Thread
     Runnable = object

+TIMEOUT_THREAD_NAME = 'RobotFrameworkTimeoutThread'

 class ThreadedRunner(Runnable):

@@ -44,7 +45,7 @@
     __call__ = run

     def run_in_thread(self, timeout):
-        self._thread = Thread(self)
+        self._thread = Thread(self, name=TIMEOUT_THREAD_NAME)
         self._thread.setDaemon(True)
         self._thread.start()
         self._notifier.wait(timeout)

Reply via email to