Sebastien Lorber
Sebastien Lorber

Reputation: 92140

Java logging best practices about logger name

I just ask about the logger name...

It it possible to give a custom name for a logger, or to use class name. But what to use in which case?

-> Using a custom name for each application module: some classes are used by 2 modules -> to which logger name should it belong to?

-> Using classname: it seems to require a good package organisation -> best practices for logging known about that?

Upvotes: 2

Views: 3249

Answers (4)

LetsSyncUp
LetsSyncUp

Reputation: 4333

I donno about anything else than class name because in any case it's very easy to read through class for locating the issue or anything else..! And it is also better to log the code using all kinda log levels e.g. trace for all possible details, fatal for exception and similarly the debud,error,info etc.

Upvotes: 1

Brian
Brian

Reputation: 6450

I've never heard of anyone use anything other than class name. I think anything else would be a mistake, leading to potential loss of logging detail down the line.

Don't overthink this one, just run with class name.

Upvotes: 1

Andreas Dolk
Andreas Dolk

Reputation: 114767

I still prefer classnames. It does not require a good package organisation but reflects your (good - hey what else?) package orgnization. And it's a common pattern to use the class names.

You can read the logging class file from the logs and set log levels on packages.

And following the common pattern prevents me from spending too much time on thinking about good (perfect) custom logger names ;-)

Upvotes: 1

Buhake Sindi
Buhake Sindi

Reputation: 89169

I prefer using class names for the purpose of debugging. You can read the log trace (and the class name will be displayed) from the log file and view line code, etc. It's useful in that sense. If someone else maintains your code, they don't have to do hectic searches on finding where the "custom name" is populated (in which class).

Upvotes: 6

Related Questions