At 05:42 PM 9/16/2006, you wrote:
>Hello every body:
>I am having some difficulties working with log4j, and I need some help
>from some one.
>I am writing a client/server application, in some way it can be compared
>with a chat client, where two or more users connect to the server
>through an applet.
>Now the applets uses classes from packages I wrote. The classes logges
>messages to no where (no logger is configured in them) I left the
>configuration for the main class, so that I can reuse those classes
>elsewhere. I am using a simple appender that I wrote, to display the
>logs in a JFrame.
>The problem is I am getting the logs from each applet displayed in it's
>own log JFrame and in the other one!!
>I am testing this on my machine, now both chat programs (applets)
>connect to the server. The first one logs the messages to both Frames !!
>And the second one does the same.
>
>At the begining of each applet I used this:
>//********************************************
>logger = Logger.getLogger(this.getClass());
>Logger.getRootLogger().addAppender(new FrameAppender(this,"Controller
>logs"));
>logger.setLevel(Level.ALL);
>BasicConfigurator.configure();
>//********************************************
>
>from what I understand, Logger.getRootLogger() is a static method,
>therefore the logger returned by it ( Logger.getRootLogger() ) is
>static, but static means for each JVM. In other words, both applets run
>in a separate JVMs, and there should be nothing shared !!!
>

Are you sure your expectation of a separate JVM for each applet is valid? From my experience, when a Java Applet is first loaded, the JVM starts up. If you go to another page, I'm pretty sure no other JVM is started. The second applet simply uses the running JVM. And based on the behavior you see, I think this is confirmed. A couple questions, though...

1. Are the two separate instances of the chat applet started in the same browser session or completely separate browsers such as Firefox and IE? 2. Are they, in fact, the same applet, or two different chat applications talking to the same server? If the JVM doesn't normally get shared across applets (which, again, may be an invalid assumption), maybe it does if the applet instances are from the same codebase? 3. Is it possible that even with separate browsers, the Java Plugin provides a single shared JVM environment across browsers?

>Now, what ever was the reason, how do I get around this ??? Let's say My
>main class is called Chat.java , and it uses another class CustomSocket.java
>What i would do in CustomSocket.java, is instantiate an object of Logger
>through  Logger.getLogger(this.getClass()), and logs  my messages
>normally. Then the application that  uses CustomSocket has to configure
>the logger (apender, Level ,....etc). How do I achive this. Please note
>that I am only newbie, and I am not looking to use configuration files.
>Just doing very basic configuration.
>If you need any more info about this problem, just please let me know, I
>'ve included what I think is relevant.

Interesting problem. Sounds like you need a repository selector that selects on classloader or some other available criteria that can provide differentiation between application instances. The problem is that repository selectors must be set once and if the applet that sets the selector is unloaded, the other applets will cease to log properly and won't be able to reset the selector, since it is protected by a guard object.

Anyone else have idea's here? I haven't had to tackle this issue in an applet environment, only a server environment where I have full control of the server.

Jake

>Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to