• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Logging events in Applet to server using log4j?

Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to use log4j for my applet application. I did, but throwing exception while writing log file.

at org.apache.log4j.Logger.getLogger(Logger.java:118)
at common.VoiceApplet.<init>(VoiceApplet.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission logs\log.txt 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:290)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:164)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:257)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:133)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:689)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
... 11 more
Exception: java.lang.ExceptionInInitializerError

I googaled and got solution


This isn't really a log4j question, because it is because your applet is running in the browser sandbox, and has no permission to create a Socket to any other host other than the host it was launched from.

You'll need to configure the applet to run out of the sandbox; effectively granting it access to connect to hosts other than the web server it was launched from before this will work.


I think you need to write a policy fie for it which grants security permission to the java files,I faced this problem in RMI implementation.

Can any one explain how to implement above solutions


Ritesh Pareek
Posts: 43016
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of the quotes are somewhat misleading. The first, because your logging code doesn't use sockets but files. Access to the local file system is indeed restricted for security reasons, but it's possible to use sockets to connect to the server where the applet was served from WITHOUT leaving the sandbox.

The second, because granting the applet access to the local file system would allow your code to run, but it doesn't help with logging to the server.

So, you need to find a way to transfer the logging information to the server, and have it logged there. The org.apache.log4j.net package supports this, in the shape of the SocketAppender (on the client) and SocketNode (on the server) classes.

Implemented this way, it should not be necessary to alter the local security policy, or to sign the applet.
Ritesh Pareek
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dittmer,

Thanks for one more valuable reply , actually i made a temporary solution, i just added a space at the bottom of my applet window and start printing log in to that window at run time, i don't have permission to access to server that's why i done it in this way.

Thanks for reply.
straws are for suckers. tiny ads are for attractive people.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic