Hi,
I want to use log4j logger or slf4j logger.
I want my logger to use log4j.properties file where I have configured my appenders.
it works in single class implementation when I use :
private static final Logger log = LoggerFactory.getLogger(IssueUpdatedListener.class); PropertyConfigurator.configure(jiraHome.getHomePath() + "\\log4j.properties");
log.error("test");
But if I have few classes it doesn't work.
I read that I need to use slf4j and configure location of log4j.properties in pom.xml
but I don't know how to do it exactly
thanks in advance
Community moderators have prevented the ability to post new answers.
I used singletone pattern and create my own PluginLogger class as following :
public class PluginLogger { private static PluginLogger uniqLoggerInstance; private static final JiraHome jiraHome = ComponentAccessor.getComponentOfType(JiraHome.class); private static Logger log; private PluginLogger(Class curClass) { log=LoggerFactory.getLogger(curClass); PropertyConfigurator.configure(jiraHome.getHomePath() + "\\log4j.properties"); } public static synchronized PluginLogger getInstance(Class curClass) { if (uniqLoggerInstance == null) { uniqLoggerInstance = new PluginLogger(curClass); } return uniqLoggerInstance; } public void printErrorLog(String input) { log.error(input); } public void printWarningLog(String input) { log.warn(input); } public void printInfoLog(String input) { log.info(input); } public void printDebugLog(String input) { log.debug(input); } }
Now at my classes I use it as following:
public class MyClass{
private PluginLogger pluginLogger;
protected MyClass()
{
pluginLogger=PluginLogger.getInstance(MyClass.class);
}
//now print to log file
pluginLogger.printErrorLog(" test logging to file");
}
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.