Log4J: Strategies for creating Logger instances

后端 未结 10 608
不思量自难忘°
不思量自难忘° 2020-11-30 21:22

I decided to use Log4J logging framework for a new Java project. I am wondering what strategy should I use for creating/managing Logger instances and why?

10条回答
  •  渐次进展
    2020-11-30 21:49

    If your application is following SOA principles, for every service A you'll have the following components:

    1. A Controller
    2. A Service Implementation
    3. A Executor
    4. A Persistance

    So it makes life easier to have a aController.log aService.log aExecutor.log and aPersistance.log

    This is a layer based separation so all your Remoting/REST/SOAP classes will write to the aController.log

    All your scheduling mechanism, backend service etc will write to aService.log

    And all task executions are written to aExecutor.log and so on.

    If you have a multi-threaded executor you might have to use a log accumulator or another technique to properly align log messages for multiple threads.

    This way you'll always have 4 log files which is not alot and not too less, I'm telling you from experience this makes life really easier.

提交回复
热议问题