Why do Java classes like java.net.InetAddress not log anything?

Viewed 92

Is there a particular reason why classes like java.net.InetAddress do not log a single line?

For certain situations it might become quite handy to have some debug information from Java library classes.

1 Answers
  1. There are many log frameworks out there. Java tried to add its own, but by then it was too late, and java's built in logging is a distant also-ran. Which gets us back to: What should it use? java.util.log, except few use that? slf4j? It's not universal and it would be a little bizarre, given that j.u.log exists. Yet another meta-layer?

  2. What would you want INetAddress to log? Creation? If you want to log the creation of some specific class, there are other tools for that, there's no need to litter log stuff into the code. Such generalized tools (a general tool that can log the creation of some specific type or the invocation of some specific method, anytime and everytime it is done) would, in one fell swoop, give you the ability to log what you need, for all the core classes, and any other class/method from any other library that doesn't log things the way you want.

  3. logging is decidedly not free. Opening a file to write data is in fact incredibly expensive, and a lot of the core libraries have to be written ignoring knuth's maxim (Premature optimization is the root of all evil - trite and oversimplified, but a popular saying) – because all sorts of code uses core libraries, so they have to be microoptimized to some extent. Logging frameworks become a lot faster if by default they don't actually end up logging (due to e.g. a level setting), but you're still on the hook for doing a lookup to check if you should be logging a thing.

More generally logging seems out of place for most of the core library stack: Logs are best used to raise important events (and the core lib has no idea what is important, it is almost by definition not 'end point' code), and to track the flow of a process, but most core libs do a single task, which means 'log it' boils down to 'log method invocations' which gets us back to #2: You can do that, you don't need java core code to explicitly have log lines included.

Related