You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I am starting to create "packages" so that my scripting is more stable and more scalable. I am using Jira Server / Scriptrunner as my means of executing said scripts.
For instance, I created a "logger" package to control default behavior on what gets logged and what does not. "debug" and "info" are normally toggled off, but "error" is normally toggled on
log = new LogThis()
log.debug("This will log because I just turned debug on")
log.info("This will NOT log because info is toggled off by default")
Backstory: I have a "controller" script that imports two other classes. Logger and Assignee. Logger is what I just explained, and the Assignee Class handles logic to "re-assign" an issue to another person. Simple enough.
Issue: I want to set the "log level" for my class in the initial script and have both Logger and Assignee instruction to respect that state. This is not going to happen if I am "newing" up LogThis in each of the two classes.
Normally, to solve this, I would "inject" the Logger into each class when I "new it up".
assignee = new Assignee(log, $issue, $assignee)
Is that best way to handle this in Groovy? I like injection and would normally make a "system" object where I store any / all frameworky objects and just inject that as SOP.
system = new System()
system.log = new LogThis()
assignee = newAssignee(system, $issue, $assignee)
As each "script" is compiled to an object, I am thinking I can not really "global" the LogThis as it is probably not available to another "imported" script just by not typecasting / def'ing the variable.
Just looking for "Best Practices" on something like this.
Thanks in advance