Log4J as a singleton


General J2EE: Log4J as a singleton

  1. Log4J as a singleton (1 messages)


    Can have only one instance of Log4J that is referenced as singleton object,and also to have information in logger what is the name of calling class.
    The problem is that once Logger is instantiated it keeps in category instance information of the first class that calls get instance method. All subsequent classes that are
    refencing the same logger will not be identified in log file - instead log will show the name of the first calling class.
    Question is how to use logger when it is called from servlets/ejb and other java classes that are referencing the same singleton logging object?

    Means I want the name of the calling class in the log file to exactly know which calling class logs the message.

    This is the question pasted by some person long time back on some other forum but found no replies . I am also facing this same problem if this couldn't be resolved than whole purpose of having logger as a singleton object would be defeated.

    Looking forward to hear replies soon.

    Mohit Gupta
  2. Log4J as a singleton[ Go to top ]

    I think create diffrent file name depending on the java files accessing the Log , It is possible to change the file name on fly.