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.
Software ProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
It shouldn't make any notable difference. The static logger is used often simply to allow logging in the context of static methods
0
Software ProgrammerAuthor Commented:
If static used will it create issue in multi thread environment...
0
CEHJCommented:
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
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Software ProgrammerAuthor Commented:
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.
0
Andrea BalassoFull Stack Java DeveloperCommented:
The static logger variable generate only one instance in the application context, instead the second logger declaration generate a new logger instance every time you create a new instance class. This means that if you have a class A and generate 1000 instance, in the first case you will have only one logger object, instead in the second case you will have 1000 instance logger object variable, one for every A instance class.
Using the static declaration you can optimize the memory resource use and this is one reason because I ususally use the static declaration for the logger.
0
CEHJCommented:
though that might depend on the framework being used
In Log4J and Logback calls are synchronized at the appending method, so you don't need to worry about issues of concurrency
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Software ProgrammerAuthor Commented:
Nice answers by both CEHJ and Andrea and fine with them.
0
Software ProgrammerAuthor Commented:
CHEJ your explanations are great..go through my remaining questions if you had time..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.