문제

While working on a web (JEE based) application I saw some different ways people have instantiated loggers in different classes. First way is classic way like,

private static final Logger logger = LoggerFactory.getLogger(AbstractPersistenceObjectDAO.class);

but as JEE applications are CDI enabled in some managed classes it was injected like

@Inject
private Logger logger;

is there any advantage if using logger with CDI, in terms of performance (time or memory)? Are there any downsides of any of these approaches? While @inject can only be used in managed environments, does it offer any advantage over other?

도움이 되었습니까?

해결책

techtrainer,

  • Use injection sparingly and only when needed
  • In my opinion there's no point in injecting logger (I use static)
  • Both costs should be negligible unless many many objects are created

Reference:

What's the overhead of creating a SLF4J loggers in static vs. non-static contexts

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top