logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mansour <mansour77+li...@ownmail.net>
Subject Re: Logger.getRootLogger() ?? is't static with respect to the JVM ?
Date Sun, 17 Sep 2006 20:18:55 GMT
Here's what I have,
1- both applications are opend in totally different browsers.
2- in fact both applications are totally different, the applets are 
(Host.java , Controller.java).
3- the last assumption might be true about firefox providing one shared 
JVM throug the plugin. I will launch a search for this, and find out 
what's going on.

I am not looking to expand my skills in log4j and use repository 
selector, as I need not to be confused about the basics. I am new to 
log4j as you know. May be in a later time, I will.

 From what I understand, is that my design for reusable component is 
correct. Again, I am creating a private logger in each class, and log to 
that logger, without configuring it. The configuration is taking place 
only in the application that uses this component, by configuring the 

So, in each class, I do this:
Logger logger = Logger.getLogger(this.getClass());
logger.info("this is a component class");

In the application class:
Logger logger = Logger.getLogger(this.getClass());
Logger.getRootLogger().addAppender(new FrameAppender(this,"Controller 

logger.info("this is the application class");

The heirerachy I am expecting is as follow:

/ | \
comp1Logger mainLogger comp2Logger

If that's correct then let me know please. I will let you know soon 
about the JVM issue. I am using Fedora 4 _64.
FireFox and JRE are built for x86_32. I had to do this to get support 
for flash. I will see what I can do.


Jacob Kjome wrote:

> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message