Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I log with Script Runner ?

Bastien Vandamme April 16, 2018

To help me to understand how Groovy and Jira libraries are working I try to log some of my values.

 

On script listeners menu of Script Runner module I can read

 

"

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

No logs were found for this execution.

"

and I can never see any of my log.info("test 1") I write

 

In "Clones an issue, and links" feature in condition box I would like to log. I woule like to log because the simple line I write seems not working.

 

3 answers

1 accepted

8 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2018

The problem is that the default level for the Scriptrunner is Error that is why you can not see messages with the info level. You have several choices

1. Go to Logging and Profiling and set the Info level for com.onresolve package. You will be able to see your logs.

2. You can set the Info level in your script:

import org.apache.log4j.Logger

import org.apache.log4j.Level

log.setLevel(Level.DEBUG)

3. You can define your own logger, which is better, and then set the INFO level for your logger.

import org.apache.log4j.Logger

import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")

In this case you should go to the System-> Logging and Profiling and set the INFO level for the com.acme.CreateSubtask logger

4 You can define your own logger and set the INFO level in your script:

import org.apache.log4j.Logger

import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")

log.setLevel(Level.DEBUG)

If you need more info on logging, you can read my article about it:

https://community.atlassian.com/t5/Jira-articles/Logging-in-ScriptRunner/ba-p/752758

Tom Van Rossom January 21, 2019 edited

I've added the following script to a custom listener on issue updated:

package be.fluidda.atlasscripts

import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger

import static org.apache.log4j.Level.DEBUG

class UpdateField extends AbstractIssueEventListener {
Logger log = Logger.getLogger("be.fluidda.atlasscripts.UpdateField")

@Override
void workflowEvent(IssueEvent event) {
log.setLevel(DEBUG)
log.error "event fired"
}
}

I've tried the 4 options you've sugested, but I keep seeing this message: 

No logs were found for this execution.

And when I browse to the logs, nothing is logged there.

Is there somewhere else I need to configure logging?

Like • Alp Erguney likes this
0 votes
stefan linsmayer February 25, 2022 edited

I had the same problem.
Nothing was logged with "log.info('my log-text')"

For me the simplest solution was to use the command log.warn("here is my logging text")

it works!

0 votes
Marcos Sanchez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 16, 2018

Hi,

Are you using the apache log4j Logger? 

import org.apache.log4j.Logger




Regards,
Marcos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events