Kathir
Kathir

Reputation: 2903

Unable to print the exact line being executed in groovy - GroovyShell?

The main groovy file (MainApp.groovy) has the following code which invokes sample.groovy

script = new GroovyShell(binding).parse(new File("sample.groovy))
script.run()

Log4j.xml has a CONSOLE appender with conversion pattern %d{ABSOLUTE} %-5p [%c{1}] %m%n.

Even by changing to different patterns the line number of the groovy file sample.groovy is not being printed during execution of methods in sample.groovy.

can someone please help me on how to print the lines which is being executed in sample.groovy?

instead of

12:40:57,255 DEBUG [sample] Request:

not it is being printed as

12:40:57,255 DEBUG [MainApp] Request:

so it is being difficult to debug or to know which line is being executed.

Thanks.

Upvotes: 0

Views: 156

Answers (1)

Nathan
Nathan

Reputation: 2062

If I understand what you're asking & without seeing the rest of your code, Log4j seems to be able to categorize this well.

In MainApp.groovy

Logger logger = Logger.getLogger(MainApp)
logger.debug("Request ${request}")

In sample.groovy:

Logger logger = Logger.getLogger(SampleApp)
logger.debug("Request ${request}")

And you should see output similar to:

2015-04-03 15:38:53,649 DEBUG  com.sample.MainApp - Request: REQUEST
2015-04-03 15:38:53,971 DEBUG  com.sample.SampleApp - Request: REQUEST

Upvotes: 1

Related Questions