java - Logback multiple loggers with different configuration -


i want use 2 different loggers in class 1 logger uses 1 logback configuration file , uses configuration file. eg:

class sample {     // logger 1 follows configuration logback1.xml     private static final logger1 = loggerfactory.getlogger(sample.class);      // logger 2 follows configuration logback2.xml     private static final logger2 = loggerfactory.getlogger(sample.class);      public myfunc(){         logger1.info("in myfunc"); // writes file configured in logback1.xml         logger2.info("entered myfunc"); // writes graylog server configured in logback2.xml     } } 

the reason want i'm injecting second logger code @ runtime, , don't want injected logger collide logger used in main project. how should go doing this?

i went through post: how use multiple configurations logback in single project? seems address problem of choosing 1 configuration file many not "being able use 2 configuration files simultaneously in above example."

this 1 way 2 loggers different configs:

    loggercontext c1 = new loggercontext();     loggercontext c2 = new loggercontext();     new contextinitializer(c1).configurebyresource(new url("file:logback1.xml"));     new contextinitializer(c2).configurebyresource(new url("file:logback2.xml"));     logger l1 = c1.getlogger("x");     logger l2 = c2.getlogger("x"); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -