I also use Weblogic and war/ear file deployment.  However, I just wrote a
simple little set of JSPs to allow dynamic overrides of the level for
defined appenders.  This is particular useful for things like user-specific
loggers...

However, I let log4j initialize itself initially from its config files.

Just some thoughts...



    |-----Original Message-----
    |From: Sébastien Hiblot [mailto:[EMAIL PROTECTED]]
    |Sent: Thursday, January 16, 2003 9:20 AM
    |To: Log4J Users List
    |Subject: RE: Help !
    |
    |
    |Thx a lot !!!
    |the problem was that we always add the appenders. So, the 
    |first time it's ok
    |but after, we always add the two appenders.....
    |
    |Now we use the exists method in order to know if the logger exists.
    |if not, we create the logger and then add the appenders.
    |if exists, we do nothing !
    |
    |You ask why we make the config in the java code.
    |For our java web site, we use Weblogic and ear file.
    |We have to specify and modify easily some parameter 
    |without deploying the
    |ear file like the level,
    |the file where we write, the repository where is the xml 
    |containing the
    |message.
    |
    |But with a config file, we can't change easily this 
    |parameters, we have to
    |deploy the ear, make the modification
    |and then rebuild the ear !
    |
    |Thx a lot for your help.
    |
    |
    |> -----Message d'origine-----
    |> De : Ebersole, Steven [mailto:[EMAIL PROTECTED]]
    |> Envoyé : jeudi 16 janvier 2003 14:54
    |> À : 'Log4J Users List'
    |> Objet : RE: Help !
    |>
    |>
    |> Step-by-step what is happening here is:
    |>
    |> First-call:
    |> 1) A logger with a name matching the given class_name 
    |does not exist, so
    |> log4j creates it.
    |> 2) Two appenders are added to the logger (a console 
    |appender and a file
    |> appender).
    |>
    |> Second-call:
    |> 1) A logger with a name matching the given class name already
    |> exists (it was
    |> created above), so that logger is returned (including 
    |the two appenders
    |> previously attached)
    |> 2) Two appenders are added to the logger (a console 
    |appender and a file
    |> appender).
    |>
    |> Etc...
    |>
    |>
    |> Assuming that there is a vaild reason you need to wrap all these
    |> log4j calls
    |> inside your own hand-rolled class, then try something 
    |like the following
    |> code change in the constructor:
    |>
    |>
    |> public Trace( String class_name )
    |> {
    |>  if (!LogManager.exists( class_name ))
    |>  {
    |>          logger = LogManager.getLogger(class_name);
    |>          Layout layout = new
    |> PatternLayout("%d{yyyyMMdd-HH:mm:ss} %m%n");
    |>          logger.addAppender(new ConsoleAppender(layout,
    |> ConsoleAppender.SYSTEM_OUT));
    |>        logger.setLevel(Level.DEBUG);
    |>          try
    |>          {
    |>                  logger.addAppender(new FileAppender(layout,
    |> 
    |(String)Ecx_constants.getInstance().get("log4j_fileTrace"), true));
    |>        }
    |>          catch (IOException e)
    |>          {}
    |>  }
    |> }
    |>
    |> But the better solution is to perform initialization of 
    |the log4j library
    |> through config files.
    |>
    |>
    |>
    |>
    |>
    |>     |-----Original Message-----
    |>     |From: Sébastien Hiblot 
    |[mailto:[EMAIL PROTECTED]]
    |>     |Sent: Thursday, January 16, 2003 7:22 AM
    |>     |To: [EMAIL PROTECTED]
    |>     |Subject: Help !
    |>     |
    |>     |
    |>     |Hi,
    |>     |
    |>     |We're working on a java web site and we'd like to use
    |>     |log4j in order
    |>     |to log the error.
    |>     |
    |>     |We have made a class to implement the init of log4j. Here
    |>     |the source of this
    |>     |class :
    |>     |
    |>     |private Logger logger ;
    |>     |
    |>     |public Trace(String class_name) {
    |>     |    logger = LogManager.getLogger(class_name);
    |>     |      Layout layout = new
    |>     |PatternLayout("%d{yyyyMMdd-HH:mm:ss} %m%n");
    |>     |      logger.addAppender(new ConsoleAppender(layout,
    |>     |ConsoleAppender.SYSTEM_OUT));
    |>     |      logger.setLevel(Level.DEBUG);
    |>     |      try {
    |>     |            logger.addAppender(new 
    |FileAppender(layout, (String)
    |>     |Ecx_constants.getInstance().get("log4j_fileTrace"), true));
    |>     |      } catch (IOException e) {
    |>     |}
    |>     |
    |>     |To log something :
    |>     |Trace t = new Trace(this.getClass().toString()) ;
    |>     |t.debug("My message");
    |>     |
    |>     |The first time, we call the page, the log contain 
    |the good thing :
    |>     |20030116-12:00:00 My message
    |>     |
    |>     |But the second time we call the page, 30 sec after, we
    |>     |have in the log:
    |>     |20030116-12:00:00 My message
    |>     |20030116-12:00:30 My message
    |>     |20030116-12:00:30 My message
    |>     |
    |>     |==> the log appears 2 times !
    |>     |the third time, the log appears 3 time, etc......
    |>     |
    |>     |Can you help us please ?
    |>     |
    |>     |Thx
    |>     |
    |>     |
    |>     |--
    |>     |To unsubscribe, e-mail:
    |>     |<mailto:[EMAIL PROTECTED]>
    |>     |For additional commands, e-mail:
    |>     |<mailto:[EMAIL PROTECTED]>
    |>     |
    |>
    |> --
    |> To unsubscribe, e-mail:
    |<mailto:[EMAIL PROTECTED]>
    |For additional commands, e-mail: 
<mailto:[EMAIL PROTECTED]>


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

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

Reply via email to