Raje Raje - 3 years ago 236
Java Question

Which is the best way to declare logger variable in java

I just wantd to know which is the best way declare logger variable in java.
Following are some declaration.

1> private static final Logger logger = Logger.getLogger(ServiceImpl.class);

2> private static Logger logger = Logger.getLogger(ServiceImpl.class);

3> private static final Logger LOGGER= Logger.getLogger(ServiceImpl.class);

4> private static Logger LOGGER= Logger.getLogger(ServiceImpl.class);

P.S I really appreciate if anybody knows another best alternative ways to declare looger variable.

Answer Source

I vote for 3

 private static final Logger LOGGER = Logger.getLogger(ServiceImpl.class);

It's final since you don't change it and it's in uppercase since it's a constant.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download