Revision: 67b03a6690ba
Branch:   default
Author:   Pekka Klärck
Date:     Mon Sep  9 11:59:29 2013 UTC
Log:      Fixed handling callable log messages in public APIs.

Update issue 1505
Status: Done
Fixed the problem by disabling the lazy logging support in the public APIs.

`robot.api.logger` now converts callables to strings automatically. `BuiltIn.Log` was fixed by changing it to use `robot.api.logger` instead of using `LOGGER` directly.
http://code.google.com/p/robotframework/source/detail?r=67b03a6690ba

Modified:
 /atest/robot/standard_libraries/builtin/log.txt
 /atest/robot/test_libraries/logging_api.txt
 /atest/testdata/standard_libraries/builtin/log.txt
 /atest/testdata/test_libraries/LibUsingLoggingApi.py
 /atest/testdata/test_libraries/logging_api.txt
 /src/robot/libraries/BuiltIn.py
 /src/robot/output/librarylogger.py

=======================================
--- /atest/robot/standard_libraries/builtin/log.txt Mon Aug 30 17:08:16 2010 UTC +++ /atest/robot/standard_libraries/builtin/log.txt Mon Sep 9 11:59:29 2013 UTC
@@ -31,6 +31,10 @@
     Check Log Message  ${tc.kws[3].msgs[0]}  <img src="nonex.png">  INFO
     Check Log Message  ${tc.kws[4].msgs[0]}  <img src="nonex.png">  HTML

+Log Callable
+    ${tc} =  Check Test Case  Log Callable
+ Check Log Message ${tc.kws[0].msgs[0]} objects_for_call_method.MyObject
+
 Log Many
     ${tc} =  Check Test Case  Log Many
     Check Log Message  ${tc.kws[0].msgs[0]}  Log Many says:  INFO
=======================================
--- /atest/robot/test_libraries/logging_api.txt Fri Jul  1 11:48:34 2011 UTC
+++ /atest/robot/test_libraries/logging_api.txt Mon Sep  9 11:59:29 2013 UTC
@@ -38,3 +38,13 @@
     Check stdout contains  To console in two parts
     Check stdout contains  To log and console
     Check log message  ${tc.kws[0].msgs[0]}  To log and console  INFO
+
+Log Non-Strings
+    ${tc} =  Check test case  ${TEST NAME}
+    Check log message  ${tc.kws[0].msgs[0]}  42
+    Check log message  ${tc.kws[0].msgs[1]}  True  WARN
+    Check log message  ${ERRORS.msgs[3]}  True  WARN
+
+Log Callable
+    ${tc} =  Check test case  ${TEST NAME}
+ Check log message ${tc.kws[0].msgs[0]} <function log_callable at *> pattern=yes
=======================================
--- /atest/testdata/standard_libraries/builtin/log.txt Mon Aug 30 16:54:57 2010 UTC +++ /atest/testdata/standard_libraries/builtin/log.txt Mon Sep 9 11:59:29 2013 UTC
@@ -29,6 +29,9 @@
     ${html} =  Set Variable  <img src="nonex.png">
     Log  ${html}
     Log  ${html}  HTML
+
+Log Callable
+    Log  ${MyObject}

 Log Many
     Log Many  Log Many says:  Hello  from  tests!
=======================================
--- /atest/testdata/test_libraries/LibUsingLoggingApi.py Mon May 9 20:26:42 2011 UTC +++ /atest/testdata/test_libraries/LibUsingLoggingApi.py Mon Sep 9 11:59:29 2013 UTC
@@ -23,3 +23,10 @@
     logger.console('To console ', newline=False)
     logger.console('in two parts')
     logger.info('To log and console', also_console=True)
+
+def log_non_strings():
+    logger.info(42)
+    logger.warn(True)
+
+def log_callable():
+    logger.info(log_callable)
=======================================
--- /atest/testdata/test_libraries/logging_api.txt Mon May 9 20:26:42 2011 UTC +++ /atest/testdata/test_libraries/logging_api.txt Mon Sep 9 11:59:29 2013 UTC
@@ -19,3 +19,9 @@

 Write messages to console
     Write messages to console
+
+Log Non-Strings
+    Log Non Strings
+
+Log Callable
+    Log Callable
=======================================
--- /src/robot/libraries/BuiltIn.py     Sun Jun  9 16:58:08 2013 UTC
+++ /src/robot/libraries/BuiltIn.py     Mon Sep  9 11:59:29 2013 UTC
@@ -15,7 +15,7 @@
 import re
 import time

-from robot.output import LOGGER, Message
+from robot.api import logger
 from robot.errors import (ContinueForLoop, DataError, ExecutionFailed,
                           ExecutionFailures, ExitForLoop, PassExecution,
                           ReturnFromKeyword)
@@ -1884,7 +1884,7 @@
         the console and in the Test Execution Errors section in the
         log file.
         """
-        LOGGER.log_message(Message(message, level))
+        logger.write(message, level)

     def log_many(self, *messages):
"""Logs the given messages as separate entries with the INFO level."""
=======================================
--- /src/robot/output/librarylogger.py  Thu Jun  6 14:00:44 2013 UTC
+++ /src/robot/output/librarylogger.py  Mon Sep  9 11:59:29 2013 UTC
@@ -21,6 +21,8 @@
 import sys
 import threading

+from robot.utils import unic
+
 from .logger import LOGGER
 from .loggerhelper import Message

@@ -29,6 +31,11 @@


 def write(msg, level, html=False):
+    # Callable messages allow lazy logging internally, but we don't want to
+ # expose this functionality publicly. See the following issue for details:
+    # http://code.google.com/p/robotframework/issues/detail?id=1505
+    if callable(msg):
+        msg = unic(msg)
     if threading.currentThread().getName() in LOGGING_THREADS:
         LOGGER.log_message(Message(msg, level, html))

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to