It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I get logging working for script runner in a script listener

John Beveridge Apr 13, 2016

JIRA 2.0.7

ScriptRunner 4.2.0.7

Hi,

I'm adding a script listener to conditionally set an issue's state based on the value of a custom field. If I leave the condition blank (true) in the script listener, the listener works as expected. However when I insert my code, it's failing. I can't seem to get any logging information.

Could I get some help enabling logging for the Script Runner listener scripts? I'm sure I can figure out why this is returning 'false' once I have more information.

Thanks,

JB>

Code in the 'Condition' field of teh script listener (Type: Fast-track transition an issue)

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def language = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_11505"))

log.info("Language:" + language)
return language == 'English'

3 answers

2 votes
Michal Partyka Apr 13, 2016

Hi John,

here you should find everything:

https://jirasupport.wordpress.com/2015/05/27/configure-groovy-scriptrunner-logs/

 

Basically you need:

log.error "Debug message"

log.debug

2 votes
John Beveridge Apr 13, 2016

Thanks for the response.

 

This doesn't work for me. I get no entry in either the atlassian-jira.log or in the 'logs' entry for the listener on the last 15 executed listeners popup.

However, when I added my own custom logger, I got logging in the listener popup but still nothing in the atlassian-jira.log.

I've done some more digging and this works as expected:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption

import org.apache.log4j.Level
import org.apache.log4j.Logger

def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def language = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_11505"))
def value = ((LazyLoadedOption)language).getValue()
myLog.debug("Test for equality: " + (value == 'English'))
return value == 'English'

I'd prefer not to have to use a custom logger. I'm wondering why your suggestion doesn't work for us.

I do have the the package 'com.onresolve.jira.groovy set up in Logging and Profiling as DEBUG.

Thanks,

JB>

Paddy Byrne Apr 13, 2016

Something like that happened me a few days ago and I discovered I set the default log to the wrong value.

image2016-4-13 23:9:56.png

Go to the admin section, find 'logging and profiling' on the left hand side and click into it. scroll down to where the logging is listed and set the 'default' one to DEBUG. When I set this back to debug, I could then see all my log.debug entries from my scripts in the last 15 executed scripts section..

 

Worked for me anyway. I think I mistakenly changed the level of this log in one of my scripts when experimenting...

0 votes
Adam Markham [Adaptavist] Community Leader Apr 13, 2016

If you want to turn on debug logging you can configure your log4j properties for this in a dev environment: https://scriptrunner.adaptavist.com/latest/common/DevEnvironment.html#_a_use_an_existing_instance

If you want a simple way of enabling debug logging temporarily you can use the code here: https://scriptrunner.adaptavist.com/latest/jira/getting-help.html#_support_requests

Otherwise its easiest to use a higher logging level:

log.warn("Logging!")

A simple test is to do logging from the script console and see if you get the message in the logs as expected.

Carsten Hilber Aug 09, 2017

I tried exactly this, logging from the Script Console in Confluence, but the Logs Tab is always empty:

import groovy.json.JsonBuilder
import org.apache.log4j.Category

import static com.atlassian.sal.api.net.Request.MethodType.POST

def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug statements"
log.warn("Logging!")
log.error("Logging!")
log.fatal("Logging!")

any idea on that?

Ron L Aug 29, 2017

I'm having the same issue where in Scripted Fields and the Script console logs work fine, but in the Custom Listener Preview log statements don't output anything under the Logs tab.

@Carsten Hilber did you figure it out on your end?

Carsten Hilber Aug 29, 2017

@Ron L nope, i skipped trying without a solution....

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

451 views 0 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you