I'm using a JIRA test environment to debug some Groovy code using ScriptRunner. I have a Listener that triggers when a certain kind of ticket is approved.
I've been trying to insert some logging into my code, but the logging isn't showing up when I change the .groovy files live on the server. This is surprising, because initially I had some errors in my code that caused exceptions, and when I changed those files on the server, the changes appeared to take effect right away.
Is there anything I have to do when I change any groovy files that live under (in my case) /var/atlassian/application-data/jira/scripts? I'm wondering if there is some JIT compilation going on that isn't noticing that I'm changing the contents of the groovy scripts.
Hi Paul,
Based on what you've said in your post, I believe that your script is updating on-the-fly.
Where logging is concerned, it's far more likely that your logging level isn't set as your expecting. By default, the only two levels that will be displayed in the log are:
log.warn("Warning")
log.error("Error")
Checking logging level
You can test this by opening your Script Console and running the following script:
log.info("info")
log.warn("warn")
log.error("error")
log.debug("debug")
log.trace("trace")
NOTE: There are other log4j levels like FATAL but I've only included these as these are the typical ones you'll work with.
Running the above script will write to your log, depending on whether or not the level is set at that point. By default your expected output will be:
2018-01-30 08:21:43,561 WARN [runner.ScriptRunnerImpl]: warn
2018-01-30 08:21:43,561 ERROR [runner.ScriptRunnerImpl]: error
Changing the logging level
WARNING: Changing your logging level will cause scripts to write more (or less) information to the log, and so should be done so with caution. I would NOT recommend doing this in a production environment unless it is absolutely necessary.
To change your log level, simply run the following command:
import org.apache.log4j.Level
log.setLevel(Level.WARN)
Ensure that you set Level.<your_desired_level> to the level that you wish to see output for in your logging.
If you want to learn more there are some really good log4j tutorials available on the web.
I hope this helps!
You indirectly answered the most important question, which is that Groovy does pick up changes on every execution.
I was in fact setting the logging level to INFO but still not getting logs. The answer turned out to be an interesting quirk of Groovy.
My old code looked like the following. The LDAPUserAction.addUserToTeam here was the one that wasn't logging correctly, despite having initialized a Logger instance variable and setting it to INFO in the object creation code.
comment = comment +"\n "+new LDAPUserAction().addUserToTeam(usrADInfo.get("sAMAccountName").toLowerCase(),
usrADInfo.get("givenName"), usrADInfo.get("sn"),
usrADInfo.get("displayName"), usrADInfo.get("mail"), teamid.getValue(), sshPublicKey)
However, when I broke the objection creation out into a separate variable, now logging worked:
def luser = new LDAPUserAction ()
comment = comment +"\n "+ luser.addUserToTeam(usrADInfo.get("sAMAccountName").toLowerCase(),
usrADInfo.get("givenName"), usrADInfo.get("sn"),
usrADInfo.get("displayName"), usrADInfo.get("mail"), teamid.getValue(), sshPublicKey)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly explain the difference between "I change the .groovy files live on the server" and "I changed those files on the server".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.