Script Runner Escalation Service custom logging

I'm looking to migrate functionality from the Jelly Services to using Script Runner Escalation Service.

What I want to do is send an email directly to assignee without necessarily updating the issue 

I've frankensteined together some code borrowed from the "Send a Custom Email" built in script and the source of the Escalation Service built in script itself to use as additional code in the Escalation Service.

I can get the service to do what I want, but I was hoping I could implement some logging within this additional code.  Any suggestion how to instantiate the correct object to be able to write to the log? 

The EscalationService.groovy includes

import org.apache.log4j.Logger
[...]
class EscalationService implements CannedScript, PluginJob {
   def log = Logger.getLogger(EscalationService.class)

But since I'm not actually defining a class  I'm not sure how else to get a logger object.

Here is what I have so far:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.MailException
import com.atlassian.mail.MailFactory
import com.atlassian.mail.queue.SingleMailQueueItem
import org.apache.log4j.Logger
def mailServerManager = ComponentAccessor.getMailServerManager();
def mailServer = mailServerManager.getDefaultSMTPMailServer();
if (mailServer && ! MailFactory.isSendingDisabled()) {
	def email = new Email( issue.assignee.emailAddress);
	email.setFrom(mailServer.getDefaultFrom())
	email.setSubject("[JIRA] Update needed: " + issue.key + " - " + issue.summary)
	email.setMimeType("text/plain");
	email.setBody("Please update https://myjirainstance.mydomain.com/browse/" + issue.key + " with the following: \n" +
	"* Current status and actions completed \n" + 
	"* Next Steps \n" +
	"* The names of those responsible for those actions, and the estimated date and time of resolution")
	try {
//		log.debug ("Sending mail to ${email.getTo()}")
//		log.debug ("with body ${email.getBody()}")
		SingleMailQueueItem item = new SingleMailQueueItem(email);
		ComponentAccessor.getMailQueue().addItem(item);
		}
	catch (MailException e) {
//		log.warn ("Error sending email", e)
		}
	}
else {
//	log.warn ("No mail server or sending disabled.")
	}

Perhaps @Jamie Echlin [Adaptavist] has an idea?

Note that I'm quite new at Groovy and even java and I probably have no business fiddling with this... but I figure that's how I'll learn.

Thanks

1 answer

This widget could not be displayed.

Hi Peter-Dave Sheenan,

The following code snippet below demonstrates what you will need to be able to write out to the atlassian-jira.log file from within your scripts.

 

// Import log4j 
import org.apache.log4j.Logger
import org.apache.log4j.Level

// Set the log level to DEBUG
log.setLevel(Level.DEBUG)

// Some examples of logging statements

// A DEBUG Statement
log.debug("An example Debug statement")

// A INFO Statement
log.info("An example Info statement")

// A Warning Statement
log.warn("An example Warming statement")

// A Error Statement
log.error("An example Error statement")

 

I hope this helps

Kristian

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

475 views 3 17
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you