0

I have an AppEngine application with Java. I am using JUL (java.util.logging) to log the server side logs. I am creating a facade call CustomLogger in which it creates a JUL logger in the constructor using the factory:

@Inject
public CustomLogger( EmailLoggingHandler handler ){
    this.logger = Logger.getLogger( "ServerLogger" );
    logger.addHandler( handler );
}

Instance of CustomLogger is bind as eagerSingleton meaning only one instance of this class will ever be instantiated per Guice instance. Everything was working until I injected the custom logger (EmailLoggingHandler) which is also part of dependency tree as a eagerSingleton.

   @Inject
    public EmailLoggingHandler( SendEmailHelper emailHelper ){
        this.emailHelper = emailHelper;
        setLevel(Level.SEVERE);
    }

The error I am getting:

Error injecting constructor, java.security.AccessControlException: access denied (java.util.logging.LoggingPermission control)  

Does anyone have any idea why this is happening?

Yahel
  • 37,023
  • 22
  • 103
  • 153
user_1357
  • 7,766
  • 13
  • 63
  • 106

1 Answers1

1

I had the same problem when I tried to hook my handler into JUL on AppEngine. I solved it by avoiding any calls to setLevel() and just using my own level variable:

public class MyHandler extends Handler {

    private Level logLevel = Level.INFO;

    @Override
    public void publish(final LogRecord record) {
        if (record.getLevel().intValue() >= logLevel.intValue())
            // ...
    }

    ...

    public void setLogLevel(final Level lvl) {
        logLevel = Level.FINE;
    }
}
stephanos
  • 3,319
  • 7
  • 33
  • 47
  • This is not an answer to the problem the questioner had. He had an AccessControlException when injecting the constructor - i.e before he had even reached the setLevel(). You need to read the question. – Dave Richardson Jan 25 '12 at 10:55
  • 1
    From my experience the problem _is_ the setLevel (and setFormatter). I can add a logger (at the top level) without a security violation in startup code, although not in the properties file where a security violation _does_ occur. – Tim Niblett Apr 02 '13 at 17:46