2 new revisions:

Revision: 0ab729959213
Author:   Pekka Klärck
Date:     Tue Sep 13 12:55:04 2011
Log: Ignore log messages originating from non-main threads to avoid possibl...
http://code.google.com/p/robotframework/source/detail?r=0ab729959213

Revision: 083af4ccf7b5
Author:   Pekka Klärck
Date:     Tue Sep 13 13:01:00 2011
Log: Documented that messages logged by non-main threads are ignored....
http://code.google.com/p/robotframework/source/detail?r=083af4ccf7b5

==============================================================================
Revision: 0ab729959213
Author:   Pekka Klärck
Date:     Tue Sep 13 12:55:04 2011
Log: Ignore log messages originating from non-main threads to avoid possible output file corruption.

Update issue 950
Status: Started
Owner: pekka.klarck
I fixed this by ignoring log messages originating from non-main threads as I planned already in the original description. Notice that this only affects messages logged using the logging APIs (robot.api.logger or logging module). Possible messages logged via stdout are handled like earlier (i.e. may end up under some other keyword or be written to the console depending).

The commit contains also tests that caused a corrupted output file every time without the fix. A remaining task is mentioning this change in the User Guide.
http://code.google.com/p/robotframework/source/detail?r=0ab729959213

Added:
 /atest/robot/test_libraries/non_main_threads_logging.txt
 /atest/testdata/test_libraries/ThreadLoggingLib.py
 /atest/testdata/test_libraries/non_main_threads_logging.txt
Modified:
 /src/robot/api/logger.py

=======================================
--- /dev/null
+++ /atest/robot/test_libraries/non_main_threads_logging.txt Tue Sep 13 12:55:04 2011
@@ -0,0 +1,17 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} test_libraries/non_main_threads_logging.txt
+Force Tags      regression  pybot  jybot
+Resource        atest_resource.txt
+
+*** Test Cases ***
+
+Log messages from non-main threads should be ignored
+    ${tc} =  Check Test Case  ${TESTNAME}
+    Should Be Empty      ${tc.kws[0].msgs}
+    Should Be Empty      ${tc.kws[1].msgs}
+    Check Log Message    ${tc.kws[2].msgs[0]}      0
+    Check Log Message    ${tc.kws[2].msgs[99]}    99
+    Length Should Be     ${tc.kws[3].msgs}       100
+    Check Log Message    ${tc.kws[3].msgs[0]}      0
+    Check Log Message    ${tc.kws[3].msgs[99]}    99
+    Length Should Be     ${tc.kws[3].msgs}       100
=======================================
--- /dev/null
+++ /atest/testdata/test_libraries/ThreadLoggingLib.py Tue Sep 13 12:55:04 2011
@@ -0,0 +1,23 @@
+import threading
+import logging
+import time
+
+from robot.api import logger
+
+
+
+def log_using_robot_api_in_thread():
+    threading.Timer(0.1, log_using_robot_api).start()
+
+def log_using_robot_api():
+    for i in range(100):
+        logger.info(str(i))
+        time.sleep(0.01)
+
+def log_using_logging_module_in_thread():
+    threading.Timer(0.1, log_using_logging_module).start()
+
+def log_using_logging_module():
+    for i in range(100):
+        logging.info(str(i))
+        time.sleep(0.01)
=======================================
--- /dev/null
+++ /atest/testdata/test_libraries/non_main_threads_logging.txt Tue Sep 13 12:55:04 2011
@@ -0,0 +1,10 @@
+*** Settings ***
+Library   ThreadLoggingLib.py
+
+*** TestCase ***
+
+Log messages from non-main threads should be ignored
+    Log using robot api in thread
+    Log using logging module in thread
+    Log using robot api
+    Log using logging module
=======================================
--- /src/robot/api/logger.py    Mon May  9 15:12:33 2011
+++ /src/robot/api/logger.py    Tue Sep 13 12:55:04 2011
@@ -52,6 +52,7 @@
 """

 import sys
+import threading

 from robot.output import LOGGER, Message

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

 def trace(msg, html=False):
     """Writes the message to the log file with the TRACE level."""

==============================================================================
Revision: 083af4ccf7b5
Author:   Pekka Klärck
Date:     Tue Sep 13 13:01:00 2011
Log:      Documented that messages logged by non-main threads are ignored.

Update issue 950
Status: Done
Added a note to the User Guide.
http://code.google.com/p/robotframework/source/detail?r=083af4ccf7b5

Modified:
 /doc/userguide/src/ExtendingRobotFramework/CreatingTestLibraries.txt

=======================================
--- /doc/userguide/src/ExtendingRobotFramework/CreatingTestLibraries.txt Tue Jul 12 13:26:10 2011 +++ /doc/userguide/src/ExtendingRobotFramework/CreatingTestLibraries.txt Tue Sep 13 13:01:00 2011
@@ -1158,6 +1158,10 @@
 background, there should be another keyword that checks the status of
 the worker thread and reports gathered information accordingly.

+.. note:: Messages logged by non-main threads using the `programmatic
+          logging APIs`_ are silently ignored starting from Robot
+          Framework 2.6.2.
+
 Distributing test libraries
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to