Revision: 43b2c874513c
Author:   Janne Härkönen <[email protected]>
Date:     Thu Aug 30 04:20:25 2012
Log:      Errors in `logging` no longer fail tests

Update issue 1212
Status: Done
Owner: janne.t.harkonen
http://code.google.com/p/robotframework/source/detail?r=43b2c874513c

Modified:
 /atest/robot/test_libraries/logging_with_logging.txt
 /atest/testdata/test_libraries/logging_with_logging.txt
 /src/robot/output/pyloggingconf.py
 /src/robot/utils/error.py

=======================================
--- /atest/robot/test_libraries/logging_with_logging.txt Thu Mar 8 05:26:05 2012 +++ /atest/robot/test_libraries/logging_with_logging.txt Thu Aug 30 04:20:25 2012
@@ -30,7 +30,13 @@
     Check log message  ${tc.kws[0].msgs[4]}  above warning             WARN

 Messages below threshold level are ignored fully
-    Check test case  ${TEST NAME}
+    ${tc}=  Check test case  ${TEST NAME}
+    Should be empty   ${tc.kws[0].msgs}
+
+Error in creating message is logged
+    ${tc}=  Check test case  ${TEST NAME}
+ Check log message ${tc.kws[0].msgs[0]} Failed to log following message: <Unrepresentable object 'InvalidMessage'. Error: Should not have been logged> + Check log message ${tc.kws[0].msgs[1]} Traceback (most recent call last):* DEBUG pattern=true

 Log using custom logger
     ${tc} =  Check test case  ${TEST NAME}
=======================================
--- /atest/testdata/test_libraries/logging_with_logging.txt Wed Jan 11 06:11:20 2012 +++ /atest/testdata/test_libraries/logging_with_logging.txt Thu Aug 30 04:20:25 2012
@@ -21,6 +21,9 @@
     [Setup]  Set log level  warn
     Log invalid message

+Error in creating message is logged
+    Log invalid message
+
 Log using custom logger
     Log using custom logger

=======================================
--- /src/robot/output/pyloggingconf.py  Thu Mar  8 05:26:05 2012
+++ /src/robot/output/pyloggingconf.py  Thu Aug 30 04:20:25 2012
@@ -15,7 +15,7 @@
 import logging

 from robot.api import logger
-
+from robot import utils

 LEVELS = {'TRACE': logging.NOTSET,
           'DEBUG': logging.DEBUG,
@@ -40,8 +40,20 @@
 class RobotHandler(logging.Handler):

     def emit(self, record):
+        message, details = self._get_message(record)
         method = self._get_logger_method(record.levelno)
-        method(record.getMessage())
+        method(message)
+        if details:
+            logger.debug(details)
+
+    def _get_message(self, record):
+        try:
+            return record.getMessage(), None
+        except Exception:
+            message = 'Failed to log following message properly: %s' % \
+                        utils.unic(record.msg)
+            details = utils.get_error_details()[1]
+            return message, details

     def _get_logger_method(self, level):
         if level >= logging.WARNING:
=======================================
--- /src/robot/utils/error.py   Tue Mar  6 00:46:30 2012
+++ /src/robot/utils/error.py   Thu Aug 30 04:20:25 2012
@@ -14,7 +14,6 @@

 import re
 import sys
-import os.path
 import traceback

 from robot.errors import RobotError

Reply via email to