简体   繁体   中英

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?

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

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 ;-)

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.

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 eg trace for all possible details, fatal for exception and similarly the debud,error,info etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM