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.
Java

Avatar of undefined
Last Comment
Software Programmer
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...
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Software Programmer

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Software Programmer

ASKER

Nice answers by both CEHJ and Andrea and fine with them.
Avatar of Software Programmer

ASKER

CHEJ your explanations are great..go through my remaining questions if you had time..
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo