Ask a Question

Using log and context variable from static method

kriti123
New Contributor

Using log and context variable from static method

I have a groovy file consisting of class with lots of static method..I want to log information within the static method and also I want to get the project path using context variable(instead of hard-coding the path) but its not allowed. Do I have an alternative??

Some excerpts from code is as below (Pls overlook the typos if its there while copying and pasting)



class wbserviceSimulation{
static main(args) {
def myclient = new RESTClient('http://127.0.0.1:8080/')
myclient.auth.basic("xxx", "yyy")
sendDocs(myclient, 'mailpiece', 'domain1', 'user1', 'user111');
}

static getProfile(RESTClient client) {
---
---
}

static sendDocs(RESTClient client, String doc, String mydomain, String normaluser, String toolUser) {
//def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
// def projectPath = groovyUtils.projectPath + '\\tool_attachments\\'
def projectPath = 'C:\\myprojects\\tool_attachments\\'
def filename= projectPath+'doc.pdf'
def meta=projectPath+'doc.xml'
-----
-----
//println "filename with extracts " + filename;
log.info ("filename with extracts " + filename)

}
}


Trying to use log or context from static method gives an error:
ERROR:An error occurred [startup failed:
Script13.groovy: 51: Apparent variable 'log' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'log' but left out brackets in a place not allowed by the grammar.
@ line 51, column 9.
log.info( "filename with extracts" + Filename);
^
1 REPLY 1
lauravachon
Contributor

Re: Using log and context variable from static method

How did you resolve this problem? I am running into the same thing

cancel
Showing results for 
Search instead for 
Did you mean: