Forum Discussion

paulie's avatar
paulie
Occasional Contributor
11 years ago

[Res]Print to script log from groovy class

I'm looking to print messages to the script log from inside one of my groovy classes. It looks like I need to pass the log instance as a parameter into the groovy class. What would be the syntax for this?
Thanks in advance.

7 Replies

  • SiKing's avatar
    SiKing
    Community Expert
    All you need is something like:

    import com.eviware.soapui.SoapUI

    def log = SoapUI.log
    log.info "Hello world!"
    log.warn "Goodbye world!"
  • paulie's avatar
    paulie
    Occasional Contributor
    Thanks SiKing but that prints in the SoaupUI log - I was hoping to print in the script log to keep all my logging together.

    I tried the the instructions from the link but didn't get it working, any ideas?
  • paulie's avatar
    paulie
    Occasional Contributor
    Hi Temil, as I'm looking to do this from an external groovy class (in my scripts directory) I get the error
    TestCase failed [groovy.lang.MissingPropertyException: No such property: log for class: Testing:groovy.lang.MissingPropertyException: No such property: log for class: Testing]

    I don't have any imports in my groovy class - should there be?
    class Testing
    {
    public testPrint()
    {
    log.info "Testing out the print from the external class"
    }
    }


    This is not vital, I can print to the SoapUI log, it just would have been nice to print to the script log to keep all my logging in one place.
    Thanks
  • paulie's avatar
    paulie
    Occasional Contributor
    Solved this - I just needed to pass log into my groovy class constructor. I had tried variations of context when it was log I really needed. Thanks to all who replied.