Forum Discussion

kriti123's avatar
New Contributor
10 years ago

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('')
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
// 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; ("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. "filename with extracts" + Filename);