Link to home
Start Free TrialLog in
Avatar of Software Programmer
Software Programmer

asked on

Defining Logger as static and non-static variable

Hi,

Sometimes in project i see a static variable defined for logger

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

in some cases i saw static is not being used and defined as

private final Logger LOGGER = Logger.getLogger(Something.class);

what is the difference between the two? Does it makes any difference in cluster and in non-cluster environment?

Thanks.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

It shouldn't make any notable difference. The static logger is used often simply to allow logging in the context of static methods
Avatar of Software Programmer
Software Programmer

ASKER

If static used will it create issue in multi thread environment...
It's conceivable, though that might depend on the framework being used. If you're doing server-side logging, it's academic really, since you wouldn't use a static logger
It is being used in the server side and saw in many projects which works in cluster environment and in a multi-threaded environment as well. So not sure how they are handling it. Do you think using static logger will cause an issue? if yes, how to use it and get rid of the multi-thread issue.
SOLUTION
Avatar of Andrea Balasso
Andrea Balasso
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice answers by both CEHJ and Andrea and fine with them.
CHEJ your explanations are great..go through my remaining questions if you had time..