Grails
  1. Grails
  2. GRAILS-7012

Special note in documentation: the 'log' variable from GroovyTestCase

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3.5
    • Fix Version/s: 1.3.7, 1.4-M1
    • Component/s: Documentation
    • Labels:
      None

      Description

      Much of the confusion over logging during the test phase seems to be related to the 'log' property.
      Throughout Grails, log4j is used as the logging framework and automagically exposed as the 'log' property. However, when writing a test case, the 'log' property (inherited from groovy.util.GroovyTestCase) is a java.util.logging.Logger. The documentation should make a note of this 'gotcha'.

      MyController.groovy
      class MyController {
        def index = {
          log.debug('This is a debug message in the controller') //log4j
        }
      }
      
      MyControllerTests.groovy
      class MyControllerTests extends ControllerUnitTestCase {
        void testIndex() {
          def model = controller.index()
          log.finer('This is a debug-ish message in the unit test code') //java.util.logging
        }
      }
      

        Activity

        Hide
        Peter Ledbrook added a comment -

        I have to admit, I didn't know about that log property.

        Show
        Peter Ledbrook added a comment - I have to admit, I didn't know about that log property.
        Hide
        Peter Ledbrook added a comment -

        Added some information about this to the user guide on the 1.3.x and master branches.

        Show
        Peter Ledbrook added a comment - Added some information about this to the user guide on the 1.3.x and master branches.

          People

          • Assignee:
            Peter Ledbrook
            Reporter:
            Brian Sanders
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development