onlyMoneyNotTalent onlyMoneyNotTalent - 4 years ago 215
Groovy Question

Using logger in groovy class for soapui

I have created the following groovy script in soapui (opensource).

import org.apache.log4j.Logger
class Test{

static String hello(){
def mylog = Logger.getLogger("")"Hello")
return mylog
} Test.hello() loge here

It does not retrieve any error message and runs, but it does not retrieve the string in the info log ( which is what I'm looking for.

Initially I thought '' would make it, which is the println equivalent when working with sopaui groovy script. But since I'm trying to write a log from a class, the class doesn't know '' by default, that's why I specified the use of 'log4j.Logger', but still not sure what I am missing.

Outside the class I put two to print the value of both logger objects (the first one is the one from my groovy class and the second the one from soapui) and this is what I got:

Thu Feb 02 17:10:56 CST 2017:INFO:org.apache.log4j.Logger@24e6b930
Thu Feb 02 17:10:56 CST 2017:INFO:org.apache.log4j.Logger@6ca396be

They look the same, except for what is after the @. Not sure what those numbers represents neither if that's part of the reason why my class does not write the info log.

If someone can help me I would appreciate it.

Rao Rao
Answer Source

Looks you are running into trivial issue.

Since log variable is already available in Groovy Script scope, you just need to pass that to your method as shown below:

Groovy Script

class MyTest{
    static String testLogging(log){"Hello")

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download