Java Logging With Abstract Classes

后端 未结 6 1236
闹比i
闹比i 2021-01-30 16:13

I am working on a project, and am currently working on implementing some logging with log4j and I was curious about how I should go about implementing the logs. The two implemen

6条回答
  •  鱼传尺愫
    2021-01-30 16:22

    Both make sense. It depends on your application.

    I think that more often used practice is to have private logger for each class. This allows you to configure logging both per class and per package. Remember, that AbstractFoo and Foo may belong to different packages and probably you want to see logs from Foo only.

    Moreover always think twice if you want to write protected field. It is not completely forbidden but a well known bad practice. It makes your code less readable and difficult to maintain.

提交回复
热议问题