I am doing a lot of work with Script Runner and I have decided to build out a semi-framework.
One of my objects is a Logger Object that helps to enforce logging consistency across all the other objects.
public class LogThis
def errorLevels = [
info : true,
In this case, using this class, all info and error messages are displayed, but debug is not. To turn on debug:
Is there a way, or is it bad practice in Groovy to make that class a global class that is accessible from inside of objects?
Currently I inject the log class into each object I instantiate:
This is a sample of calling a class that will change the assignee on an issue. I am injecting the log object into the Assignees object.
I find that very, very repetitive, and not expandable. If I need to start injecting another object, and another object, my class signature start to get unweildy at some point.
My inclination is to create some form of Dependency Injection Container (or IoC Container, etc, etc), but I have no idea if Groovy can handle that, or if it's even a Best Practice in Groovy.
This is kind of an "advanced" topic, but hopefully somebody wants to geek out on this subject :-)
Thanks in advance.
You could use the singleton design pattern: https://en.wikipedia.org/wiki/Singleton_pattern
Instead of injecting the logger into each class, the class could obtain it by calling the "getInstace()" method or just doing it the Groovy way: "Logger.instance".
Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events