menacher/java-game-server

How to disable log4j for applet?

nikolaykuz opened this issue · 2 comments

There is line in the code

PropertyConfigurator.configure(properties);

If run my app as applet it generates this error/warning in Java Plugin Console. This is normal behavior because applet is not supposed to perform external io operations. But how I can disable log with out any warnings?

java.security.AccessControlException: access denied ("java.io.FilePermission" "log\GameClient.log" "write")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkWrite(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207)
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
    at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
    at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:809)
    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
    at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
    at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:428)
log4j:WARN No appenders could be found for logger (org.evogame.client.swing.AppletApp).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 

If I comment the code line still

AppletApp.init()
log4j:WARN No appenders could be found for logger (org.evogame.client.swing.AppletApp).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
basic: Applet initialized

Is this server or client? Client is not having a dependency on log4j. At server side, one option I can think of is, change the properties file to have ConsoleAppender instead of file appender and then turn the logging off.
log4j.appender.toLogFile=org.apache.log4j.ConsoleAppender. I have not tried this in applet so not sure if it will work.

It was a client. I just forget to eliminate this kind of lines:

private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);