multithreading - Java: Logging for multiple Threads with Log4j2 -


let's have 3 classes a, b , c working in separate threads (ta, tb, , tc) , of them have own instance of logger.

now got mess in ouput because there no order in loggings of 3 classes. there possiblity sort loggings in order of appearance?

for example:

class {     public static final logger logger = loggerfactory.getlogger(a.class);      public void start() {         logger.info("testa");         logger.info("testa");         logger.info("testa");     } }  class b {     public static final logger logger = loggerfactory.getlogger(b.class);      public void start() {         logger.info("testb");         logger.info("testb");         logger.info("testb");     } }  class {     public static final logger logger = loggerfactory.getlogger(c.class);      public void start() {         logger.info("testc");         logger.info("testc");         logger.info("testc");     } } 

output:

testa testa testb testb testa testc testc testb testc 

what want is:

testa testa testa testb testb testb testc testc testc 

since logging definition time-based, doesn't make sense try think achieve (well, without additional work of course).

what can add thread id logging layout. can use other tools (e.g. grep) isolate logging specific threads wish see, or sort log thread id give logs each thread sequentially.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -