Forums

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

Trying to debug but logs flooded with messages

John Wedding June 4, 2024

I have what appears to be a relatively straightforward listener:

-----------------------------------------------------

log.warn("started")
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def customFieldManager = ComponentAccessor.customFieldManager
def issue = event.issue
def issueType = issue.issueType.name

// This is the existing selector field
def loeDevSelectorFieldObject = customFieldManager.getCustomFieldObject(11100)
def loeDevSelectorField = issue.getCustomFieldValue(loeDevSelectorFieldObject)

// This is the (new) Double field to do summing over in reports
def loeDevNumberFieldObject = customFieldManager.getCustomFieldObject(11801)
def loeDevNumberField = issue.getCustomFieldValue(loeDevNumberFieldObject)
def dLoe = 0 as Double
assert loeDevNumberField : "Could not find custom field with name 'LOE Development'"
assert loeDevSelectorField : "Could not find custom field with name 'Level Of Effort - Development'"
if (!issueType.equals("Bug") && !issueType.equals("Feature")) { return }
log.warn("got past type guard")
if (loeDevSelectorField.toString().equals("0")) { dLoe = 0 }
if (loeDevSelectorField.toString().equals("1")) { dLoe = 1 }
if (loeDevSelectorField.toString().equals("2")) { dLoe = 2 }
if (loeDevSelectorField.toString().equals("3")) { dLoe = 3 }
if (loeDevSelectorField.toString().equals("5")) { dLoe = 5 }
if (loeDevSelectorField.toString().equals("8")) { dLoe = 8 }
if (loeDevSelectorField.toString().equals("13")) { dLoe = 13 }

loeDevNumberFieldObject.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(loeDevNumberFieldObject), dLoe as Double), new DefaultIssueChangeHolder())
--------------------------------------------------

But most of the executions are failing and the information I need is likely truncated away from the top of the log because I get hundreds of "at" messages:

----------------------------------------

at com.atlassian.jira.event.issue.DefaultIssueEventManager.publishEventIfNotificationsAreEnabled(DefaultIssueEventManager.java:180) ~[classes/:?] at com.atlassian.jira.event.issue.DefaultIssueEventManager.publishEvent(DefaultIssueEventManager.java:175) ~[classes/:?] at com.atlassian.jira.event.issue.DefaultIssueEventManager.dispatchIssueEventBundle(DefaultIssueEventManager.java:129) ~[classes/:?] at com.atlassian.jira.workflow.function.event.FireIssueEventFunction.execute(FireIssueEventFunction.java:73) ~[classes/:?] at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1014) ~[osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1] at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1407) ~[osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]

[... many many similar messages deleted ...]

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-coyote.jar:9.0.80] at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-util.jar:9.0.80] at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-util.jar:9.0.80] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-util.jar:9.0.80] at java.lang.Thread.run(Thread.java:829) ~[?:?]

Start of logs truncated as they exceeded 300 lines.

-----------------------------------------

 

I found this question that talks about the ScriptRunner version and such:

https://community.atlassian.com/t5/Jira-questions/300-lines-of-error-at-transition/qaq-p/2180085

I have ScriptRunner 8.15.0 and Jira 9.11.2

Any hints?

Thanks, R/ John

1 answer

1 accepted

1 vote
Answer accepted
PD Sheehan
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.
June 4, 2024

You can review the full log by consulting the <jira-home>log/altassian-jira.log file.

You can access that same log using the built-in script "view server log files".

If you want, you can trap your error and then output a manageable number of stack trace messages so don't get flooded.

try {
//all your code here
} catch (e){
def stackTraceIndex = e.stackTrace.findIndexOf{ it.className.contains('groovy')}
if(stackTraceIndex < 1) stackTraceIndex = 20 //default in case we don't find is
log.error e.errorMessage + '\n' + e.stackTrace.take(stackTraceIndex + 5).join('\n')
}

This will only output up to the first line that contains the keyword groovy, or the first 25 lines otherwise.

 

But it appears that you are just trying to convert the values of a select list into a number.

That can be greatly simplified with HAPI:

def issueTypesAllowed = ['Bug', 'Feature']
if(!issueTypesAllowed.contains(issue.issueType.name) ) return //nothing to do if issue type is not in the list
def selectFielId = 11100L
def numberFieldId = 11801L
def selectValue = issue.getCustomFieldValue(selectFielId)?.value
if(!selectValue) return //no value selected
issue.update{
setCustomFieldValue(numberFieldId, selectValue )
}

This will handle the conversion from String to Double and take care of the history and indexing.

John Wedding June 5, 2024

Thank you so much for the wonderful answer! I'll give this a try.

You're correct; that's exactly what I was looking to do.

John Wedding June 5, 2024

Thanks very much for this.

I tried the try-catch block, however the rest of the messages continue to blow past the 300-line limit.

Your code at the bottom, though, works perfectly. Definitely simpler than what I had, and clearly more correct, haha!

Suggest an answer

Log in or Sign up to answer