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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

118 views 0 4
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