1

I created a class MyLogger that extends java.util.Logger in my project and I want each class to use the same logger therefore there is a static getLogger() method which returns a Logger object.

The plan is for this to be a jar file that can be included in other people's programs, but I don't want them to be able to use this custom logger (ie. if they want logging they need to set it up themselves with their own logger).

Is there any way to allow the MyLogger class be in its own package while allowing the rest of the classes in my project/jar be able to access the getLogger() method, but not allow classes outside my project to call it (kinda like package private, but for the whole project) or is the only way to put it in my "parent" package?

yitzih
  • 3,018
  • 3
  • 27
  • 44

1 Answers1

2

Yes, you may noticed you can not put a class into package java.util, the technology is the JSA. You could use the SecurityManager (who uses the accesscontroller). If the library who is calling the logger-event is not certified by your private certificate, it throws the unchecked AccessControlException.

You will find a good example in the FileOutputStream like this:

SecurityManager security = System.getSecurityManager();
if (security != null) {
    security.checkWrite(name); // throws ACE
}

To authenticate a complete JVM and disable the checks you could add the private key to jdk-xxx/jre/lib/security/cacerts (keystore).

Grim
  • 1,938
  • 10
  • 56
  • 123