You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Jacob Kjome <ho...@visi.com> on 2007/04/10 06:44:16 UTC

Re: separate log files for application's on weblogic with log4j using RepositorySelector

1.  Use non-static loggers (for Serializable classes, you'll need to 
mark these as transient)
2.  Avoid Classloader-based repository selectors.  Use JNDI-base 
selectors.  There's already one written for Log4j-1.3alpha.  Even if 
you don't care to use 1.3, you can use it to get an idea of how to 
write one for 1.2.


See:
http://www.qos.ch/logging/sc.jsp
http://wiki.apache.org/jakarta-commons/Logging/StaticLog


Jake

At 03:09 PM 4/9/2007, you wrote:
 >
 >I followed some examples on the web to use RepositorySelector to implement
 >separate logging for 2 applications deployed on the same instance of
 >weblogic server. I have the Lgo4j.properties file under Web-Inf/ folder,
 >This is loaded through web.xml file through a startup servlet. Problem is
 >logging is taking place either in Log4j.log file or other applications log
 >file. In each java class file, I use..
 >       private static Logger log = Logger.getLogger(LoginFilter.class);
 >and call the log .info ..accordingly. In log4j properties file, only
 >difference is file name for 2 applications.
 >
 >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
 >
 >thanks for the help
 >Sohan
 >
 >web.xml entry...
 >
 >       <servlet>
 >               <servlet-name>log4j-init</servlet-name>
 >               <servlet-class>pcs.common.util.Log4jInit</servlet-class>
 >           <init-param>
 >                   <param-name>Log4JProperties</param-name>
 >                   <param-value>/WEB-INF/log4j-dev.properties</param-value>
 >           </init-param>
 >           <init-param>
 >                   <param-name>LogToFileOnly</param-name>
 >                   <param-value>false</param-value>
 >           </init-param>
 >               <load-on-startup>1</load-on-startup>
 >       </servlet>
 >
 >public class Log4jInit extends HttpServlet {
 >       static Logger log = Logger.getLogger(Log4jInit.class);
 >       public void init() throws ServletException {
 > 
System.out.println("\n\n---------------Log4jInit---------------\n\n"); 

 >               MyRepositorySelector.init(this.getServletConfig());
 >               Logger log = Logger.getLogger(this.getClass());
 >               log.info("Log message from Log4jInit servlet");
 >               System.out.println("\n\n---------------Log4jInit:
 >Complete---------------\n\n");
 >
 >       }
 >
 >}
 >
 >public class MyRepositorySelector implements RepositorySelector
 >{
 >   private static boolean initialized = false;
 >   private static Object guard = LogManager.getRootLogger();
 >
 >   private static Map repositories = new HashMap();
 >   private static LoggerRepository defaultRepository;
 >
 >   public static synchronized void init(ServletConfig config)
 >        throws ServletException {
 >      if( !initialized ) // set the global RepositorySelector
 >      {
 >         defaultRepository = LogManager.getLoggerRepository();
 >         RepositorySelector theSelector = new MyRepositorySelector();
 >         LogManager.setRepositorySelector(theSelector, guard);
 >         initialized = true;
 >      }
 >
 >      Hierarchy hierarchy = new Hierarchy(new RootCategory(Level.DEBUG));
 >      loadLog4JConfig(config, hierarchy);
 >      ClassLoader loader = Thread.currentThread().getContextClassLoader();
 >      repositories.put(loader, hierarchy);
 >   }
 >
 >   public static synchronized void removeFromRepository() {
 >       repositories.remove(Thread.currentThread().getContextClassLoader());
 >   }
 >
 >
 >   private static void loadLog4JConfig(ServletConfig config,
 >                                       Hierarchy hierarchy)
 >                                            throws ServletException {
 >        try {
 >
 >               String strLogProperties =
 > 
config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
 >               System.out.println("strLogProperties: " + strLogProperties);
 >               Properties logProperties = new Properties();
 >               try {
 >
 >logProperties.load(config.getServletContext().getResourceAsStream(strL
 >ogProperties));
 >               } catch (Exception e) {
 >                       System.out.println("ERROR: Loading log4j 
properties: " +
 >e.getMessage());
 >                       //e.printStackTrace();
 >               }
 >               PropertyConfigurator propConf = new PropertyConfigurator();
 >            propConf.doConfigure(logProperties, hierarchy);
 >                       } catch (Exception e) {
 >            throw new ServletException(e);
 >        }
 >    }
 >
 >   private MyRepositorySelector() {
 >   }
 >
 >   public LoggerRepository getLoggerRepository() {
 >      ClassLoader loader = Thread.currentThread().getContextClassLoader();
 >      LoggerRepository repository =
 >(LoggerRepository)repositories.get(loader);
 >
 >      if (repository == null) {
 >          return defaultRepository;
 >      } else {
 >          return repository;
 >      }
 >   }
 >}
 >--
 >View this message in context:
 >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
 >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >
 >
 >---------------------------------------------------------------------
 >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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by sohan <so...@mms.gov>.
Once again thanks jake,
upgraded to 1.2.14 version and good thing is I did not encounter any
weblogic errors and my log is rolling too.

To set file name for the log dynamically, I do..
logProperties.setProperty("webApp.name", webAppName);
Is there anything similar to this for xml formatted properties file? I don't
want to use System properties, I need to be able to set this per each
application.

thanks,
Sohan


Jacob Kjome wrote:
> 
>  >Thanks Jake, Changing from Servlet to ServletContextListener helped,
>  >accordingly I changed web.xml and applications are now logging to
>  >independent log files.
>  >
>  >I have hit another block though with DailyRollingFileAppender, I changed
> one
>  >applications properties to use DailyRollingFileAppender to roll over
>  >everyminute for test purposes, If I understand correctly, rollover
> happens
>  >if there is any logging to take place based on before and after the
> minute.
>  >Instead my log file is just growing as if it is set to
> RollingFileAppender.
>  >Restarted server few times too.
>  >I have followed the properties example from chapter 3 from the manual,
> it
>  >says the date pattern should be .yyyy-MM-dd-HH-mm. I tried both ways
>  >.yyyy-MM-dd-HH-mm and '.'yyyy-MM-dd-HH-m but the log is not rolling
> over.
>  >what is the correct syntax? ofcourse the manual is for 1.2.9 version and
> I
>  >am using 1.2.8. What could be the reason for log file not rolling over.
> I am
>  >running weblogic server on my local machine as myself with all the
>  >privileges. Below is the properties listed.
>  >
> 
> I'm not sure of the exact syntax, off the top of my head, but first 
> things first.  The obvious first step in resolving this is to upgrade 
> to the latest Log4j release, which is 1.2.14.  Many fixes have been 
> made to Log4j since 1.2.8; even since 1.2.9, for that matter.  This 
> might solve your issue.  If it does not, report back and we'll try to 
> address it.
> 
> Jake
> 
>  >Thanks for your patience and help,
>  >Sohan
>  >
>  >log4j.rootLogger=ERROR, FILE, CONSOLE
>  >log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
>  >log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
>  >%m%n
>  >log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
> %m%n
>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p
> %c:%L -
>  >%m%n
>  >log4j.logger.regs=DEBUG
>  >log4j.logger.doc=DEBUG
>  >
>  >#log4j.appender.FILE=org.apache.log4j.RollingFileAppender
>  >log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
>  >log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
>  >log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
> %m%n
>  >log4j.appender.FILE.File=regs.log
>  >log4j.appender.ROLL.DatePattern='.'yyyy-MM-dd-HH-mm
>  >#log4j.appender.FILE.MaxFileSize=1MB
>  >#log4j.appender.FILE.MaxBackupIndex=2
>  >
>  >
>  >
>  >Jacob Kjome wrote:
>  >>
>  >> At 05:13 PM 4/12/2007, you wrote:
>  >>  >
>  >>  >I have tried many ways to get this to work..partly successful but
>  >> overall
>  >>  >can't this to work. I even purchased the manual and reviewed it.
>  >>  >
>  >>  >Tried Log4j 1.3, It was like opening a can of worms..weblogic 8.1.6
>  >> internal
>  >>  >logging complained, had to revert back to Log4j 1.2 version.
>  >>  >
>  >>
>  >> That's too bad.  Of course this is why there will most likely never
>  >> be an official release of 1.3.  It's currently too incompatible with
>  >> 1.2.xx.
>  >>
>  >>  >Earlier I was able to log only class files extending Httpservlet
> which
>  >> were
>  >>  >identified in web.xml file with load-on-startup values set to 1 and
> 2.
>  >>  >Looking closely at weblogic startup script, found a configuration
> file
>  >> being
>  >>  >set there for weblogic workshop with -Dlog4j.configuration property,
>  >> once I
>  >>  >commented this out, I was able to log from other class files of the
>  >>  >application however "filter" class files are not being logged, Based
> on
>  >>  >System.out.... statements, console shows that these filter classes
> are
>  >> being
>  >>  >loaded even before the servlet object initializing log4j
>  >> RepositorySelector
>  >>  >with load-on-startup set to 1 is loaded  At this point I am not
> getting
>  >>  >default log4j.log file either. Basically, my filter log is lost.
> Tried
>  >>  >getLogger("pcs") based on logger configuration in properties file,
>  >> didn't
>  >>  >get any errors not logging.
>  >>  >
>  >>
>  >> Why in the world are you using a Servlet to perform Log4j
>  >> initialization?  That's what a ServletContextListener is for, and it
>  >> will certainly be loaded before any other webapp resources get
>  >> loaded, such as servlets or filters.  And if that fails, you can
>  >> always write a Weblogic startup class (see the Weblogic docs) that
>  >> installs the repository selector at Weblogic startup time, before any
>  >> apps get loaded.
>  >>
>  >> And why don't you lower the level of your root logger in the
>  >> configuration to be DEBUG instead of ERROR?  Not permanently, just
>  >> until you verify that you are getting logging output, at which point
>  >> you can set it back.
>  >>
>  >>  >I made similar changes to my second application, basically copied
> the
>  >>  >MyRepositorySelector.java file changed the Log4jinit.java file to
> set
>  >>  >RepositorySelector and Log4j.properties file or Log4j.xml file are
>  >> similar
>  >>  >with exception of the "log4j.appender.FILE.File",
> "log4j.logger.regs"
>  >>  >entries, in bold below. Configuration file names are the same.
>  >>  >In this case both log files are being created, however, the
> application
>  >> that
>  >>  >is loaded last during startup, only that application's log is being
>  >> created.
>  >>  >First application's log is not being written after initialization
>  >> entries,
>  >>  >unless second application is either removed or changes related to
>  >>  >RepositorySelector are reverted.
>  >>  >
>  >>
>  >> Probably an issue with using a classloader-based repository selector
>  >> rather than a JNDI-based one.
>  >>
>  >>  >log4j.rootLogger=ERROR, FILE, CONSOLE
>  >>  >log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
>  >>  >log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
>  >>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p
> %c -
>  >>  >%m%n
>  >>  >log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p
> %l -
>  >> %m%n
>  >>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p
>  >> %c:%L -
>  >>  >%m%n
>  >>  >log4j.logger.regs=DEBUG
>  >>  >log4j.logger.doc=DEBUG
>  >>  >log4j.appender.FILE=org.apache.log4j.RollingFileAppender
>  >>  >log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
>  >>  >log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
>  >> %m%n
>  >>  >log4j.appender.FILE.File=regs.log
>  >>  >log4j.appender.FILE.MaxFileSize=1MB
>  >>  >log4j.appender.FILE.MaxBackupIndex=2
>  >>  >
>  >>  >After 3 days, At this point I am not sure if I can get this to work!
>  >>  >
>  >>
>  >> I know how frustrating it can be.  But did you try the
>  >> ContextJNDISelector from the Log4j sandbox?  It is 1.2 compatible.  I
>  >> can't promise you it will work in Weblogic because I haven't tried it
>  >> with that server, but it's worth a shot.  Here's the link again....
>  >>
>  >>
>  >http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/
>  >LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
>  >>
>  >>
>  >> Jake
>  >>
>  >>  >thanks,
>  >>  >Sohan
>  >>  >
>  >>  >
>  >>  >
>  >>  >Jacob Kjome wrote:
>  >>  >>
>  >>  >>
>  >>  >> Looks mostly correct.  You could change jakarta.apache.org or
>  >>  >> logging.apache.org, but that's inconsequential.  Also, you should
>  >> apply a
>  >>  >> level
>  >>  >> to the root logger, such as <level value="WARN"/>, or maybe set it
> to
>  >>  >> DEBUG for
>  >>  >> testing.
>  >>  >>
>  >>  >> See the Log4j Wiki [1] for links to WizardForge (look at the
> bottom of
>  >> the
>  >>  >> page), which will walk you through the steps of generating valid
> Log4j
>  >> 1.2
>  >>  >> and
>  >>  >> 1.3 compatible config files.
>  >>  >>
>  >>  >> Just to be clear, I'm not advocating moving to Log4j 1.3, as it
> may
>  >> never
>  >>  >> be
>  >>  >> fully released outside of alpha builds.  I just want to to try it
> out
>  >>  >> since it
>  >>  >> currently has a working JNDIContextSelector that you can use to
> test
>  >>  >> against.
>  >>  >> It's a selector that I know, at least in my testing, works.  If
> you
>  >> find
>  >>  >> it to
>  >>  >> work for you, you can adapt it to create your own selector which
> would
>  >> be
>  >>  >> compatible with Log4j 1.2.  I also forgot to mention that I
> created a
>  >>  >> Log4j-1.2
>  >>  >> compatible ContextJNDISelector in the log4j sandbox [2].  It works
>  >>  >> slightly
>  >>  >> differently than the one in Log4j-1.3, but it might provide a good
>  >> base
>  >>  >> for you
>  >>  >> to start from.
>  >>  >>
>  >>  >> [1] http://wiki.apache.org/logging-log4j/Log4JProjectPages
>  >>  >> [2]
>  >>  >>
>  >> 
> >http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/
>  >>  >LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
>  >>  >>
>  >>  >>
>  >>  >> Jake
>  >>  >>
>  >>  >> Quoting sohan <so...@mms.gov>:
>  >>  >>
>  >>  >>>
>  >>  >>> Hi jake,
>  >>  >>>
>  >>  >>> Before I start using Log4j-1.3, I want to confirm if my Log4j.xml
> is
>  >>  >>> valid
>  >>  >>> for my requirements
>  >>  >>> Below is the xml..I removed SYSTEM entry as I was getting
> log4j.dtd
>  >> file
>  >>  >>> not
>  >>  >>> found error during weblogic startup.
>  >>  >>> In this xml do I need to specify logger entry? Am I missing
> anything!
>  >>  >>>
>  >>  >>> thanks,
>  >>  >>> Sohan
>  >>  >>>
>  >>  >>> <?xml version="1.0" encoding="UTF-8"?>
>  >>  >>> <!DOCTYPE log4j:configuration >
>  >>  >>>
>  >>  >>> <log4j:configuration
> xmlns:log4j="http://jakarta.apache.org/log4j/"
>  >>  >>> debug="false">
>  >>  >>>
>  >>  >>>    <!-- A time/date based rolling appender -->
>  >>  >>>    <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log
> -->
>  >>  >>>    <!-- <appender name="TEST"
>  >>  >>> class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
>  >>  >>>    <appender name="TEST"
>  >> class="org.apache.log4j.RollingFileAppender">
>  >>  >>>       <!-- <errorHandler
>  >>  >>> class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
>  >>  >>>       <param name="File" value="pcs.log"/>
>  >>  >>>       <param name="Append" value="false"/>
>  >>  >>>
>  >>  >>>       <!-- Rollover at midnight each day -->
>  >>  >>>        <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->
>  >>  >>>
>  >>  >>>       <layout class="org.apache.log4j.PatternLayout">
>  >>  >>>          <!-- The default pattern: Date Priority [Category]
> Message\n
>  >> -->
>  >>  >>>          <param name="ConversionPattern" value="%d %-5p [%c]
> %m%n"/>
>  >>  >>>
>  >>  >>>          <!-- The full pattern: Date MS Priority [Category]
>  >> (Thread:NDC)
>  >>  >>> Message\n
>  >>  >>>          <param name="ConversionPattern" value="%d %-5r %-5p [%c]
>  >> (%t:%x)
>  >>  >>> %m%n"/>
>  >>  >>>           -->
>  >>  >>>       </layout>
>  >>  >>>    </appender>
>  >>  >>>
>  >>  >>>    <!-- ======================= -->
>  >>  >>>    <!-- Setup the Root category -->
>  >>  >>>    <!-- ======================= -->
>  >>  >>>
>  >>  >>>    <root>
>  >>  >>>       <appender-ref ref="TEST"/>
>  >>  >>>    </root>
>  >>  >>>
>  >>  >>> </log4j:configuration>
>  >>  >>>
>  >>  >>>
>  >>  >>> Jacob Kjome wrote:
>  >>  >>> >
>  >>  >>> >
>  >>  >>> > Have you tried using the JNDI repository selector solution,
> such as
>  >>  >>> > in Log4j-1.3?  To test this out quickly, you could just try
> using
>  >>  >>> > Log4j-1.3 and its ContextJNDISelector class to perform the
>  >> repository
>  >>  >>> > selection.  I know it works.  I'm not sure why you are seeing
> odd
>  >>  >>> > results with the classloader-based selector you wrote, but I
>  >> haven't
>  >>  >>> > gone over the code intensively either.  In any case, don't use
> a
>  >>  >>> > classloader-based approach.  It will give you nothing but
>  >> headaches,
>  >>  >>> > in my experience.
>  >>  >>> >
>  >>  >>> > Add the following to your server startup script...
>  >>  >>> >
>  >>  >>> > -Dlog4j.repositorySelector=JNDI
>  >>  >>> >
>  >>  >>> >
>  >>  >>> > Add the following to your web.xml....
>  >>  >>> >
>  >>  >>> >      <listener>
>  >>  >>> >          <!-- this feature may require building Log4j-1.3 from
>  >>  >>> > source, as it may not be in the latest released alpha jar???
> -->
>  >>  >>> >
>  >>  >>> >
>  >>  >>>
>  >>  >>
>  >> 
> ><listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL<
>  >>  >/listener-class>
>  >>  >>> >      </listener>
>  >>  >>> >
>  >>  >>> >      <env-entry>
>  >>  >>> >          <description>JNDI logging context for this
>  >> app</description>
>  >>  >>> >          <env-entry-name>log4j/context-name</env-entry-name>
>  >>  >>> >          <env-entry-value>myapp</env-entry-value>
>  >>  >>> >          <env-entry-type>java.lang.String</env-entry-type>
>  >>  >>> >      </env-entry>
>  >>  >>> >
>  >>  >>> >      <env-entry>
>  >>  >>> >          <description>URL for configuring log4j
>  >> context</description>
>  >>  >>> >
>  >> <env-entry-name>log4j/configuration-resource</env-entry-name>
>  >>  >>> >          <env-entry-value>myapp-log4j.xml</env-entry-value>
>  >>  >>> >          <env-entry-type>java.lang.String</env-entry-type>
>  >>  >>> >      </env-entry>
>  >>  >>> >
>  >>  >>> >
>  >>  >>> > Jake
>  >>  >>> >
>  >>  >>> > At 07:08 PM 4/10/2007, you wrote:
>  >>  >>> >  >
>  >>  >>> >  >"What do you mean "'pcs' is the log file name"?  That would
> be
>  >> the
>  >>  >>> > logger
>  >>  >>> >  >name,
>  >>  >>> >  >not the file name."
>  >>  >>> >  >My mistake, I meant to say that it is both the logger name as
>  >> well as
>  >>  >>> I
>  >>  >>> >  >named the log file name same too after the application name.
>  >>  >>> >  > I tried with both LogFactory of commons-logging as well as
>  >> direct
>  >>  >>> use
>  >>  >>> > of
>  >>  >>> >  >Log4j. Behavior is the same
>  >>  >>> >  >I did notice one thing, Log information is being written
> normally
>  >>  >>> from
>  >>  >>> > java
>  >>  >>> >  >classes that extend HttpServlet.
>  >>  >>> >  >Logging from other java class files is not working as
> intended.
>  >> My
>  >>  >>> >  >application uses struts 1.2.9 too.
>  >>  >>> >  >
>  >>  >>> >  >thanks,
>  >>  >>> >  >Sohan
>  >>  >>> >  >
>  >>  >>> >  >
>  >>  >>> >  >Jacob Kjome wrote:
>  >>  >>> >  >>
>  >>  >>> >  >> Quoting sohan <so...@mms.gov>:
>  >>  >>> >  >>
>  >>  >>> >  >>>
>  >>  >>> >  >>> I changed to use Log4j.xml from Log4j.properties and also
>  >> changed
>  >>  >>> to
>  >>  >>> >  >>> non-static loggers and with in the static methods followed
> the
>  >>  >>> link
>  >>  >>> >  >>> examples. Now the logging is taking place only for the
> loggers
>  >>  >>> > mentioned
>  >>  >>> >  >>> in
>  >>  >>> >  >>> the static methods, Log log = LogFactory.getLog("pcs");
> pcs is
>  >> the
>  >>  >>> > log
>  >>  >>> >  >>> file
>  >>  >>> >  >>> name.
>  >>  >>> >  >>>
>  >>  >>> >  >>
>  >>  >>> >  >> What do you mean "'pcs' is the log file name"?  That would
> be
>  >> the
>  >>  >>> > logger
>  >>  >>> >  >> name,
>  >>  >>> >  >> not the file name.
>  >>  >>> >  >>
>  >>  >>> >  >> Also, I didn't mean to direct you to use commons-logging. 
> If
>  >> you
>  >>  >>> were
>  >>  >>> >  >> using
>  >>  >>> >  >> log4j directly, please keep using it.  In fact, log
> wrappers
>  >> like
>  >>  >>> > SLF4J
>  >>  >>> >  >> and
>  >>  >>> >  >> commons-logging have issues when it comes to repository
>  >> selectors.
>  >>  >>> > Search
>  >>  >>> >  >> the
>  >>  >>> >  >> SLF4J user list for details on this.  There's also a bug in
> the
>  >>  >>> SLF4J
>  >>  >>> >  >> database
>  >>  >>> >  >> about this.  I believe the same applies to commons-logging.
>  >> Log4j
>  >>  >>> > cannot
>  >>  >>> >  >> guarantee proper logging separation when you use a wrapper.
>  >>  >>> >  >>
>  >>  >>> >  >>> Any idea as to why the non static logger is not working!
>  >>  >>> >  >>>
>  >>  >>> >  >>
>  >>  >>> >  >> I would guess it's because you are using commons-logging. 
> Use
>  >>  >>> Log4j
>  >>  >>> >  >> directly,
>  >>  >>> >  >> just as you were previously.  I only sent you the
>  >> commons-logging
>  >>  >>> link
>  >>  >>> >  >> because
>  >>  >>> >  >> they had a good synopsis of the static logger issue, not to
>  >>  >>> convince
>  >>  >>> > you
>  >>  >>> >  >> to
>  >>  >>> >  >> move to commons-logging.
>  >>  >>> >  >>
>  >>  >>> >  >>
>  >>  >>> >  >> Jake
>  >>  >>> >  >>
>  >>  >>> >  >>> thanks,
>  >>  >>> >  >>> Sohan
>  >>  >>> >  >>>
>  >>  >>> >  >>>
>  >>  >>> >  >>> Jacob Kjome wrote:
>  >>  >>> >  >>> >
>  >>  >>> >  >>> >
>  >>  >>> >  >>> > 1.  Use non-static loggers (for Serializable classes,
> you'll
>  >>  >>> need
>  >>  >>> > to
>  >>  >>> >  >>> > mark these as transient)
>  >>  >>> >  >>> > 2.  Avoid Classloader-based repository selectors.  Use
>  >> JNDI-base
>  >>  >>> >  >>> > selectors.  There's already one written for
> Log4j-1.3alpha.
>  >>  >>> Even
>  >>  >>> > if
>  >>  >>> >  >>> > you don't care to use 1.3, you can use it to get an idea
> of
>  >> how
>  >>  >>> to
>  >>  >>> >  >>> > write one for 1.2.
>  >>  >>> >  >>> >
>  >>  >>> >  >>> >
>  >>  >>> >  >>> > See:
>  >>  >>> >  >>> > http://www.qos.ch/logging/sc.jsp
>  >>  >>> >  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>  >>  >>> >  >>> >
>  >>  >>> >  >>> >
>  >>  >>> >  >>> > Jake
>  >>  >>> >  >>> >
>  >>  >>> >  >>> > At 03:09 PM 4/9/2007, you wrote:
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >I followed some examples on the web to use
>  >> RepositorySelector
>  >>  >>> to
>  >>  >>> >  >>> > implement
>  >>  >>> >  >>> >  >separate logging for 2 applications deployed on the
> same
>  >>  >>> instance
>  >>  >>> > of
>  >>  >>> >  >>> >  >weblogic server. I have the Lgo4j.properties file
> under
>  >>  >>> Web-Inf/
>  >>  >>> >  >>> folder,
>  >>  >>> >  >>> >  >This is loaded through web.xml file through a startup
>  >> servlet.
>  >>  >>> >  >>> Problem
>  >>  >>> >  >>> > is
>  >>  >>> >  >>> >  >logging is taking place either in Log4j.log file or
> other
>  >>  >>> >  >>> applications
>  >>  >>> >  >>> > log
>  >>  >>> >  >>> >  >file. In each java class file, I use..
>  >>  >>> >  >>> >  >       private static Logger log =
>  >>  >>> >  >>> Logger.getLogger(LoginFilter.class);
>  >>  >>> >  >>> >  >and call the log .info ..accordingly. In log4j
> properties
>  >>  >>> file,
>  >>  >>> > only
>  >>  >>> >  >>> >  >difference is file name for 2 applications.
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >thanks for the help
>  >>  >>> >  >>> >  >Sohan
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >web.xml entry...
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >       <servlet>
>  >>  >>> >  >>> >  >               <servlet-name>log4j-init</servlet-name>
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
>  >>  >>> >  >>> >  >           <init-param>
>  >>  >>> >  >>> >  >
>  >> <param-name>Log4JProperties</param-name>
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
>  >>  >>> >  >>> >  >           </init-param>
>  >>  >>> >  >>> >  >           <init-param>
>  >>  >>> >  >>> >  >                  
> <param-name>LogToFileOnly</param-name>
>  >>  >>> >  >>> >  >                   <param-value>false</param-value>
>  >>  >>> >  >>> >  >           </init-param>
>  >>  >>> >  >>> >  >               <load-on-startup>1</load-on-startup>
>  >>  >>> >  >>> >  >       </servlet>
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >public class Log4jInit extends HttpServlet {
>  >>  >>> >  >>> >  >       static Logger log =
>  >> Logger.getLogger(Log4jInit.class);
>  >>  >>> >  >>> >  >       public void init() throws ServletException {
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >
>  >>  >>> >
>  >> System.out.println("\n\n---------------Log4jInit---------------\n\n");
>  >>  >>> >  >>> >
>  >>  >>> >  >>> >  >
>  >>  >>> > MyRepositorySelector.init(this.getServletConfig());
>  >>  >>> >  >>> >  >               Logger log =
>  >> Logger.getLogger(this.getClass());
>  >>  >>> >  >>> >  >               log.info("Log message from Log4jInit
>  >> servlet");
>  >>  >>> >  >>> >  >
>  >>  >>> System.out.println("\n\n---------------Log4jInit:
>  >>  >>> >  >>> >  >Complete---------------\n\n");
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >       }
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >}
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >public class MyRepositorySelector implements
>  >>  >>> RepositorySelector
>  >>  >>> >  >>> >  >{
>  >>  >>> >  >>> >  >   private static boolean initialized = false;
>  >>  >>> >  >>> >  >   private static Object guard =
>  >> LogManager.getRootLogger();
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >   private static Map repositories = new HashMap();
>  >>  >>> >  >>> >  >   private static LoggerRepository defaultRepository;
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >   public static synchronized void init(ServletConfig
>  >> config)
>  >>  >>> >  >>> >  >        throws ServletException {
>  >>  >>> >  >>> >  >      if( !initialized ) // set the global
>  >> RepositorySelector
>  >>  >>> >  >>> >  >      {
>  >>  >>> >  >>> >  >         defaultRepository =
>  >> LogManager.getLoggerRepository();
>  >>  >>> >  >>> >  >         RepositorySelector theSelector = new
>  >>  >>> > MyRepositorySelector();
>  >>  >>> >  >>> >  >         LogManager.setRepositorySelector(theSelector,
>  >> guard);
>  >>  >>> >  >>> >  >         initialized = true;
>  >>  >>> >  >>> >  >      }
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
>  >>  >>> >  >>> > RootCategory(Level.DEBUG));
>  >>  >>> >  >>> >  >      loadLog4JConfig(config, hierarchy);
>  >>  >>> >  >>> >  >      ClassLoader loader =
>  >>  >>> >  >>> > Thread.currentThread().getContextClassLoader();
>  >>  >>> >  >>> >  >      repositories.put(loader, hierarchy);
>  >>  >>> >  >>> >  >   }
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >   public static synchronized void
> removeFromRepository()
>  >> {
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >
>  >>  >>> >
>  >> repositories.remove(Thread.currentThread().getContextClassLoader());
>  >>  >>> >  >>> >  >   }
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >   private static void loadLog4JConfig(ServletConfig
>  >> config,
>  >>  >>> >  >>> >  >                                       Hierarchy
>  >> hierarchy)
>  >>  >>> >  >>> >  >                                            throws
>  >>  >>> > ServletException {
>  >>  >>> >  >>> >  >        try {
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >               String strLogProperties =
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >
> config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
>  >>  >>> >  >>> >  >               System.out.println("strLogProperties: "
> +
>  >>  >>> >  >>> > strLogProperties);
>  >>  >>> >  >>> >  >               Properties logProperties = new
>  >> Properties();
>  >>  >>> >  >>> >  >               try {
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >
>  >>  >>> >  >>>
>  >>  >>> >
>  >>
> >logProperties.load(config.getServletContext().getResourceAsStream(strL
>  >>  >>> >  >>> >  >ogProperties));
>  >>  >>> >  >>> >  >               } catch (Exception e) {
>  >>  >>> >  >>> >  >                       System.out.println("ERROR:
> Loading
>  >>  >>> log4j
>  >>  >>> >  >>> > properties: " +
>  >>  >>> >  >>> >  >e.getMessage());
>  >>  >>> >  >>> >  >                       //e.printStackTrace();
>  >>  >>> >  >>> >  >               }
>  >>  >>> >  >>> >  >               PropertyConfigurator propConf = new
>  >>  >>> >  >>> > PropertyConfigurator();
>  >>  >>> >  >>> >  >            propConf.doConfigure(logProperties,
>  >> hierarchy);
>  >>  >>> >  >>> >  >                       } catch (Exception e) {
>  >>  >>> >  >>> >  >            throw new ServletException(e);
>  >>  >>> >  >>> >  >        }
>  >>  >>> >  >>> >  >    }
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >   private MyRepositorySelector() {
>  >>  >>> >  >>> >  >   }
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >   public LoggerRepository getLoggerRepository() {
>  >>  >>> >  >>> >  >      ClassLoader loader =
>  >>  >>> >  >>> > Thread.currentThread().getContextClassLoader();
>  >>  >>> >  >>> >  >      LoggerRepository repository =
>  >>  >>> >  >>> >  >(LoggerRepository)repositories.get(loader);
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >      if (repository == null) {
>  >>  >>> >  >>> >  >          return defaultRepository;
>  >>  >>> >  >>> >  >      } else {
>  >>  >>> >  >>> >  >          return repository;
>  >>  >>> >  >>> >  >      }
>  >>  >>> >  >>> >  >   }
>  >>  >>> >  >>> >  >}
>  >>  >>> >  >>> >  >--
>  >>  >>> >  >>> >  >View this message in context:
>  >>  >>> >  >>> >
>  >>  >>> >  >>>
>  >>  >>> >
>  >>
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>  >>> >  >>> >
>  >> >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
>  >>  >>> >  >>> >  >Sent from the Log4j - Users mailing list archive at
>  >>  >>> Nabble.com.
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >  >
>  >>  >>> >  >>> >
>  >>  >>> >
>  >> >---------------------------------------------------------------------
>  >>  >>> >  >>> >  >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 this message in context:
>  >>  >>> >  >>>
>  >>  >>> >  >>
>  >>  >>> >
>  >>  >>>
>  >>
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>  >>> > 
> >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
>  >>  >>> >  >>> Sent from the Log4j - Users mailing list archive at
>  >> Nabble.com.
>  >>  >>> >  >>>
>  >>  >>> >  >>>
>  >>  >>> >  >>>
>  >>  >>>
> ---------------------------------------------------------------------
>  >>  >>> >  >>> 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 this message in context:
>  >>  >>> >
>  >>  >>>
>  >>
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>  >>> > 
> >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
>  >>  >>> >  >Sent from the Log4j - Users mailing list archive at
> Nabble.com.
>  >>  >>> >  >
>  >>  >>> >  >
>  >>  >>> >
>  >> >---------------------------------------------------------------------
>  >>  >>> >  >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 this message in context:
>  >>  >>>
>  >>  >>
>  >> 
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
>  >>  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >>  >>>
>  >>  >>>
>  >>  >>>
> ---------------------------------------------------------------------
>  >>  >>> 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 this message in context:
>  >> 
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9969473
>  >>  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >>  >
>  >>  >
>  >> 
> >---------------------------------------------------------------------
>  >>  >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 this message in context:
>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9987150
>  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >
>  >
>  >---------------------------------------------------------------------
>  >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 this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a10025611
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by Jacob Kjome <ho...@visi.com>.
At 04:56 PM 4/13/2007, you wrote:
 >
 >Thanks Jake, Changing from Servlet to ServletContextListener helped,
 >accordingly I changed web.xml and applications are now logging to
 >independent log files.
 >
 >I have hit another block though with DailyRollingFileAppender, I changed one
 >applications properties to use DailyRollingFileAppender to roll over
 >everyminute for test purposes, If I understand correctly, rollover happens
 >if there is any logging to take place based on before and after the minute.
 >Instead my log file is just growing as if it is set to RollingFileAppender.
 >Restarted server few times too.
 >I have followed the properties example from chapter 3 from the manual, it
 >says the date pattern should be .yyyy-MM-dd-HH-mm. I tried both ways
 >.yyyy-MM-dd-HH-mm and '.'yyyy-MM-dd-HH-m but the log is not rolling over.
 >what is the correct syntax? ofcourse the manual is for 1.2.9 version and I
 >am using 1.2.8. What could be the reason for log file not rolling over. I am
 >running weblogic server on my local machine as myself with all the
 >privileges. Below is the properties listed.
 >

I'm not sure of the exact syntax, off the top of my head, but first 
things first.  The obvious first step in resolving this is to upgrade 
to the latest Log4j release, which is 1.2.14.  Many fixes have been 
made to Log4j since 1.2.8; even since 1.2.9, for that matter.  This 
might solve your issue.  If it does not, report back and we'll try to 
address it.

Jake

 >Thanks for your patience and help,
 >Sohan
 >
 >log4j.rootLogger=ERROR, FILE, CONSOLE
 >log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
 >log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
 >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
 >%m%n
 >log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
 >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c:%L -
 >%m%n
 >log4j.logger.regs=DEBUG
 >log4j.logger.doc=DEBUG
 >
 >#log4j.appender.FILE=org.apache.log4j.RollingFileAppender
 >log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
 >log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 >log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
 >log4j.appender.FILE.File=regs.log
 >log4j.appender.ROLL.DatePattern='.'yyyy-MM-dd-HH-mm
 >#log4j.appender.FILE.MaxFileSize=1MB
 >#log4j.appender.FILE.MaxBackupIndex=2
 >
 >
 >
 >Jacob Kjome wrote:
 >>
 >> At 05:13 PM 4/12/2007, you wrote:
 >>  >
 >>  >I have tried many ways to get this to work..partly successful but
 >> overall
 >>  >can't this to work. I even purchased the manual and reviewed it.
 >>  >
 >>  >Tried Log4j 1.3, It was like opening a can of worms..weblogic 8.1.6
 >> internal
 >>  >logging complained, had to revert back to Log4j 1.2 version.
 >>  >
 >>
 >> That's too bad.  Of course this is why there will most likely never
 >> be an official release of 1.3.  It's currently too incompatible with
 >> 1.2.xx.
 >>
 >>  >Earlier I was able to log only class files extending Httpservlet which
 >> were
 >>  >identified in web.xml file with load-on-startup values set to 1 and 2.
 >>  >Looking closely at weblogic startup script, found a configuration file
 >> being
 >>  >set there for weblogic workshop with -Dlog4j.configuration property,
 >> once I
 >>  >commented this out, I was able to log from other class files of the
 >>  >application however "filter" class files are not being logged, Based on
 >>  >System.out.... statements, console shows that these filter classes are
 >> being
 >>  >loaded even before the servlet object initializing log4j
 >> RepositorySelector
 >>  >with load-on-startup set to 1 is loaded  At this point I am not getting
 >>  >default log4j.log file either. Basically, my filter log is lost. Tried
 >>  >getLogger("pcs") based on logger configuration in properties file,
 >> didn't
 >>  >get any errors not logging.
 >>  >
 >>
 >> Why in the world are you using a Servlet to perform Log4j
 >> initialization?  That's what a ServletContextListener is for, and it
 >> will certainly be loaded before any other webapp resources get
 >> loaded, such as servlets or filters.  And if that fails, you can
 >> always write a Weblogic startup class (see the Weblogic docs) that
 >> installs the repository selector at Weblogic startup time, before any
 >> apps get loaded.
 >>
 >> And why don't you lower the level of your root logger in the
 >> configuration to be DEBUG instead of ERROR?  Not permanently, just
 >> until you verify that you are getting logging output, at which point
 >> you can set it back.
 >>
 >>  >I made similar changes to my second application, basically copied the
 >>  >MyRepositorySelector.java file changed the Log4jinit.java file to set
 >>  >RepositorySelector and Log4j.properties file or Log4j.xml file are
 >> similar
 >>  >with exception of the "log4j.appender.FILE.File", "log4j.logger.regs"
 >>  >entries, in bold below. Configuration file names are the same.
 >>  >In this case both log files are being created, however, the application
 >> that
 >>  >is loaded last during startup, only that application's log is being
 >> created.
 >>  >First application's log is not being written after initialization
 >> entries,
 >>  >unless second application is either removed or changes related to
 >>  >RepositorySelector are reverted.
 >>  >
 >>
 >> Probably an issue with using a classloader-based repository selector
 >> rather than a JNDI-based one.
 >>
 >>  >log4j.rootLogger=ERROR, FILE, CONSOLE
 >>  >log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
 >>  >log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
 >>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
 >>  >%m%n
 >>  >log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
 >> %m%n
 >>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p
 >> %c:%L -
 >>  >%m%n
 >>  >log4j.logger.regs=DEBUG
 >>  >log4j.logger.doc=DEBUG
 >>  >log4j.appender.FILE=org.apache.log4j.RollingFileAppender
 >>  >log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 >>  >log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
 >> %m%n
 >>  >log4j.appender.FILE.File=regs.log
 >>  >log4j.appender.FILE.MaxFileSize=1MB
 >>  >log4j.appender.FILE.MaxBackupIndex=2
 >>  >
 >>  >After 3 days, At this point I am not sure if I can get this to work!
 >>  >
 >>
 >> I know how frustrating it can be.  But did you try the
 >> ContextJNDISelector from the Log4j sandbox?  It is 1.2 compatible.  I
 >> can't promise you it will work in Weblogic because I haven't tried it
 >> with that server, but it's worth a shot.  Here's the link again....
 >>
 >>
 >http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/
 >LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
 >>
 >>
 >> Jake
 >>
 >>  >thanks,
 >>  >Sohan
 >>  >
 >>  >
 >>  >
 >>  >Jacob Kjome wrote:
 >>  >>
 >>  >>
 >>  >> Looks mostly correct.  You could change jakarta.apache.org or
 >>  >> logging.apache.org, but that's inconsequential.  Also, you should
 >> apply a
 >>  >> level
 >>  >> to the root logger, such as <level value="WARN"/>, or maybe set it to
 >>  >> DEBUG for
 >>  >> testing.
 >>  >>
 >>  >> See the Log4j Wiki [1] for links to WizardForge (look at the bottom of
 >> the
 >>  >> page), which will walk you through the steps of generating valid Log4j
 >> 1.2
 >>  >> and
 >>  >> 1.3 compatible config files.
 >>  >>
 >>  >> Just to be clear, I'm not advocating moving to Log4j 1.3, as it may
 >> never
 >>  >> be
 >>  >> fully released outside of alpha builds.  I just want to to try it out
 >>  >> since it
 >>  >> currently has a working JNDIContextSelector that you can use to test
 >>  >> against.
 >>  >> It's a selector that I know, at least in my testing, works.  If you
 >> find
 >>  >> it to
 >>  >> work for you, you can adapt it to create your own selector which would
 >> be
 >>  >> compatible with Log4j 1.2.  I also forgot to mention that I created a
 >>  >> Log4j-1.2
 >>  >> compatible ContextJNDISelector in the log4j sandbox [2].  It works
 >>  >> slightly
 >>  >> differently than the one in Log4j-1.3, but it might provide a good
 >> base
 >>  >> for you
 >>  >> to start from.
 >>  >>
 >>  >> [1] http://wiki.apache.org/logging-log4j/Log4JProjectPages
 >>  >> [2]
 >>  >>
 >>  >http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/
 >>  >LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
 >>  >>
 >>  >>
 >>  >> Jake
 >>  >>
 >>  >> Quoting sohan <so...@mms.gov>:
 >>  >>
 >>  >>>
 >>  >>> Hi jake,
 >>  >>>
 >>  >>> Before I start using Log4j-1.3, I want to confirm if my Log4j.xml is
 >>  >>> valid
 >>  >>> for my requirements
 >>  >>> Below is the xml..I removed SYSTEM entry as I was getting log4j.dtd
 >> file
 >>  >>> not
 >>  >>> found error during weblogic startup.
 >>  >>> In this xml do I need to specify logger entry? Am I missing anything!
 >>  >>>
 >>  >>> thanks,
 >>  >>> Sohan
 >>  >>>
 >>  >>> <?xml version="1.0" encoding="UTF-8"?>
 >>  >>> <!DOCTYPE log4j:configuration >
 >>  >>>
 >>  >>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
 >>  >>> debug="false">
 >>  >>>
 >>  >>>    <!-- A time/date based rolling appender -->
 >>  >>>    <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log -->
 >>  >>>    <!-- <appender name="TEST"
 >>  >>> class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
 >>  >>>    <appender name="TEST"
 >> class="org.apache.log4j.RollingFileAppender">
 >>  >>>       <!-- <errorHandler
 >>  >>> class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
 >>  >>>       <param name="File" value="pcs.log"/>
 >>  >>>       <param name="Append" value="false"/>
 >>  >>>
 >>  >>>       <!-- Rollover at midnight each day -->
 >>  >>>        <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->
 >>  >>>
 >>  >>>       <layout class="org.apache.log4j.PatternLayout">
 >>  >>>          <!-- The default pattern: Date Priority [Category] Message\n
 >> -->
 >>  >>>          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
 >>  >>>
 >>  >>>          <!-- The full pattern: Date MS Priority [Category]
 >> (Thread:NDC)
 >>  >>> Message\n
 >>  >>>          <param name="ConversionPattern" value="%d %-5r %-5p [%c]
 >> (%t:%x)
 >>  >>> %m%n"/>
 >>  >>>           -->
 >>  >>>       </layout>
 >>  >>>    </appender>
 >>  >>>
 >>  >>>    <!-- ======================= -->
 >>  >>>    <!-- Setup the Root category -->
 >>  >>>    <!-- ======================= -->
 >>  >>>
 >>  >>>    <root>
 >>  >>>       <appender-ref ref="TEST"/>
 >>  >>>    </root>
 >>  >>>
 >>  >>> </log4j:configuration>
 >>  >>>
 >>  >>>
 >>  >>> Jacob Kjome wrote:
 >>  >>> >
 >>  >>> >
 >>  >>> > Have you tried using the JNDI repository selector solution, such as
 >>  >>> > in Log4j-1.3?  To test this out quickly, you could just try using
 >>  >>> > Log4j-1.3 and its ContextJNDISelector class to perform the
 >> repository
 >>  >>> > selection.  I know it works.  I'm not sure why you are seeing odd
 >>  >>> > results with the classloader-based selector you wrote, but I
 >> haven't
 >>  >>> > gone over the code intensively either.  In any case, don't use a
 >>  >>> > classloader-based approach.  It will give you nothing but
 >> headaches,
 >>  >>> > in my experience.
 >>  >>> >
 >>  >>> > Add the following to your server startup script...
 >>  >>> >
 >>  >>> > -Dlog4j.repositorySelector=JNDI
 >>  >>> >
 >>  >>> >
 >>  >>> > Add the following to your web.xml....
 >>  >>> >
 >>  >>> >      <listener>
 >>  >>> >          <!-- this feature may require building Log4j-1.3 from
 >>  >>> > source, as it may not be in the latest released alpha jar??? -->
 >>  >>> >
 >>  >>> >
 >>  >>>
 >>  >>
 >>  ><listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL<
 >>  >/listener-class>
 >>  >>> >      </listener>
 >>  >>> >
 >>  >>> >      <env-entry>
 >>  >>> >          <description>JNDI logging context for this
 >> app</description>
 >>  >>> >          <env-entry-name>log4j/context-name</env-entry-name>
 >>  >>> >          <env-entry-value>myapp</env-entry-value>
 >>  >>> >          <env-entry-type>java.lang.String</env-entry-type>
 >>  >>> >      </env-entry>
 >>  >>> >
 >>  >>> >      <env-entry>
 >>  >>> >          <description>URL for configuring log4j
 >> context</description>
 >>  >>> >
 >> <env-entry-name>log4j/configuration-resource</env-entry-name>
 >>  >>> >          <env-entry-value>myapp-log4j.xml</env-entry-value>
 >>  >>> >          <env-entry-type>java.lang.String</env-entry-type>
 >>  >>> >      </env-entry>
 >>  >>> >
 >>  >>> >
 >>  >>> > Jake
 >>  >>> >
 >>  >>> > At 07:08 PM 4/10/2007, you wrote:
 >>  >>> >  >
 >>  >>> >  >"What do you mean "'pcs' is the log file name"?  That would be
 >> the
 >>  >>> > logger
 >>  >>> >  >name,
 >>  >>> >  >not the file name."
 >>  >>> >  >My mistake, I meant to say that it is both the logger name as
 >> well as
 >>  >>> I
 >>  >>> >  >named the log file name same too after the application name.
 >>  >>> >  > I tried with both LogFactory of commons-logging as well as
 >> direct
 >>  >>> use
 >>  >>> > of
 >>  >>> >  >Log4j. Behavior is the same
 >>  >>> >  >I did notice one thing, Log information is being written normally
 >>  >>> from
 >>  >>> > java
 >>  >>> >  >classes that extend HttpServlet.
 >>  >>> >  >Logging from other java class files is not working as intended.
 >> My
 >>  >>> >  >application uses struts 1.2.9 too.
 >>  >>> >  >
 >>  >>> >  >thanks,
 >>  >>> >  >Sohan
 >>  >>> >  >
 >>  >>> >  >
 >>  >>> >  >Jacob Kjome wrote:
 >>  >>> >  >>
 >>  >>> >  >> Quoting sohan <so...@mms.gov>:
 >>  >>> >  >>
 >>  >>> >  >>>
 >>  >>> >  >>> I changed to use Log4j.xml from Log4j.properties and also
 >> changed
 >>  >>> to
 >>  >>> >  >>> non-static loggers and with in the static methods followed the
 >>  >>> link
 >>  >>> >  >>> examples. Now the logging is taking place only for the loggers
 >>  >>> > mentioned
 >>  >>> >  >>> in
 >>  >>> >  >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is
 >> the
 >>  >>> > log
 >>  >>> >  >>> file
 >>  >>> >  >>> name.
 >>  >>> >  >>>
 >>  >>> >  >>
 >>  >>> >  >> What do you mean "'pcs' is the log file name"?  That would be
 >> the
 >>  >>> > logger
 >>  >>> >  >> name,
 >>  >>> >  >> not the file name.
 >>  >>> >  >>
 >>  >>> >  >> Also, I didn't mean to direct you to use commons-logging.  If
 >> you
 >>  >>> were
 >>  >>> >  >> using
 >>  >>> >  >> log4j directly, please keep using it.  In fact, log wrappers
 >> like
 >>  >>> > SLF4J
 >>  >>> >  >> and
 >>  >>> >  >> commons-logging have issues when it comes to repository
 >> selectors.
 >>  >>> > Search
 >>  >>> >  >> the
 >>  >>> >  >> SLF4J user list for details on this.  There's also a bug in the
 >>  >>> SLF4J
 >>  >>> >  >> database
 >>  >>> >  >> about this.  I believe the same applies to commons-logging.
 >> Log4j
 >>  >>> > cannot
 >>  >>> >  >> guarantee proper logging separation when you use a wrapper.
 >>  >>> >  >>
 >>  >>> >  >>> Any idea as to why the non static logger is not working!
 >>  >>> >  >>>
 >>  >>> >  >>
 >>  >>> >  >> I would guess it's because you are using commons-logging.  Use
 >>  >>> Log4j
 >>  >>> >  >> directly,
 >>  >>> >  >> just as you were previously.  I only sent you the
 >> commons-logging
 >>  >>> link
 >>  >>> >  >> because
 >>  >>> >  >> they had a good synopsis of the static logger issue, not to
 >>  >>> convince
 >>  >>> > you
 >>  >>> >  >> to
 >>  >>> >  >> move to commons-logging.
 >>  >>> >  >>
 >>  >>> >  >>
 >>  >>> >  >> Jake
 >>  >>> >  >>
 >>  >>> >  >>> thanks,
 >>  >>> >  >>> Sohan
 >>  >>> >  >>>
 >>  >>> >  >>>
 >>  >>> >  >>> Jacob Kjome wrote:
 >>  >>> >  >>> >
 >>  >>> >  >>> >
 >>  >>> >  >>> > 1.  Use non-static loggers (for Serializable classes, you'll
 >>  >>> need
 >>  >>> > to
 >>  >>> >  >>> > mark these as transient)
 >>  >>> >  >>> > 2.  Avoid Classloader-based repository selectors.  Use
 >> JNDI-base
 >>  >>> >  >>> > selectors.  There's already one written for Log4j-1.3alpha.
 >>  >>> Even
 >>  >>> > if
 >>  >>> >  >>> > you don't care to use 1.3, you can use it to get an idea of
 >> how
 >>  >>> to
 >>  >>> >  >>> > write one for 1.2.
 >>  >>> >  >>> >
 >>  >>> >  >>> >
 >>  >>> >  >>> > See:
 >>  >>> >  >>> > http://www.qos.ch/logging/sc.jsp
 >>  >>> >  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
 >>  >>> >  >>> >
 >>  >>> >  >>> >
 >>  >>> >  >>> > Jake
 >>  >>> >  >>> >
 >>  >>> >  >>> > At 03:09 PM 4/9/2007, you wrote:
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >I followed some examples on the web to use
 >> RepositorySelector
 >>  >>> to
 >>  >>> >  >>> > implement
 >>  >>> >  >>> >  >separate logging for 2 applications deployed on the same
 >>  >>> instance
 >>  >>> > of
 >>  >>> >  >>> >  >weblogic server. I have the Lgo4j.properties file under
 >>  >>> Web-Inf/
 >>  >>> >  >>> folder,
 >>  >>> >  >>> >  >This is loaded through web.xml file through a startup
 >> servlet.
 >>  >>> >  >>> Problem
 >>  >>> >  >>> > is
 >>  >>> >  >>> >  >logging is taking place either in Log4j.log file or other
 >>  >>> >  >>> applications
 >>  >>> >  >>> > log
 >>  >>> >  >>> >  >file. In each java class file, I use..
 >>  >>> >  >>> >  >       private static Logger log =
 >>  >>> >  >>> Logger.getLogger(LoginFilter.class);
 >>  >>> >  >>> >  >and call the log .info ..accordingly. In log4j properties
 >>  >>> file,
 >>  >>> > only
 >>  >>> >  >>> >  >difference is file name for 2 applications.
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >thanks for the help
 >>  >>> >  >>> >  >Sohan
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >web.xml entry...
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >       <servlet>
 >>  >>> >  >>> >  >               <servlet-name>log4j-init</servlet-name>
 >>  >>> >  >>> >  >
 >>  >>> >  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
 >>  >>> >  >>> >  >           <init-param>
 >>  >>> >  >>> >  >
 >> <param-name>Log4JProperties</param-name>
 >>  >>> >  >>> >  >
 >>  >>> >  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
 >>  >>> >  >>> >  >           </init-param>
 >>  >>> >  >>> >  >           <init-param>
 >>  >>> >  >>> >  >                   <param-name>LogToFileOnly</param-name>
 >>  >>> >  >>> >  >                   <param-value>false</param-value>
 >>  >>> >  >>> >  >           </init-param>
 >>  >>> >  >>> >  >               <load-on-startup>1</load-on-startup>
 >>  >>> >  >>> >  >       </servlet>
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >public class Log4jInit extends HttpServlet {
 >>  >>> >  >>> >  >       static Logger log =
 >> Logger.getLogger(Log4jInit.class);
 >>  >>> >  >>> >  >       public void init() throws ServletException {
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >
 >>  >>> >
 >> System.out.println("\n\n---------------Log4jInit---------------\n\n");
 >>  >>> >  >>> >
 >>  >>> >  >>> >  >
 >>  >>> > MyRepositorySelector.init(this.getServletConfig());
 >>  >>> >  >>> >  >               Logger log =
 >> Logger.getLogger(this.getClass());
 >>  >>> >  >>> >  >               log.info("Log message from Log4jInit
 >> servlet");
 >>  >>> >  >>> >  >
 >>  >>> System.out.println("\n\n---------------Log4jInit:
 >>  >>> >  >>> >  >Complete---------------\n\n");
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >       }
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >}
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >public class MyRepositorySelector implements
 >>  >>> RepositorySelector
 >>  >>> >  >>> >  >{
 >>  >>> >  >>> >  >   private static boolean initialized = false;
 >>  >>> >  >>> >  >   private static Object guard =
 >> LogManager.getRootLogger();
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >   private static Map repositories = new HashMap();
 >>  >>> >  >>> >  >   private static LoggerRepository defaultRepository;
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >   public static synchronized void init(ServletConfig
 >> config)
 >>  >>> >  >>> >  >        throws ServletException {
 >>  >>> >  >>> >  >      if( !initialized ) // set the global
 >> RepositorySelector
 >>  >>> >  >>> >  >      {
 >>  >>> >  >>> >  >         defaultRepository =
 >> LogManager.getLoggerRepository();
 >>  >>> >  >>> >  >         RepositorySelector theSelector = new
 >>  >>> > MyRepositorySelector();
 >>  >>> >  >>> >  >         LogManager.setRepositorySelector(theSelector,
 >> guard);
 >>  >>> >  >>> >  >         initialized = true;
 >>  >>> >  >>> >  >      }
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
 >>  >>> >  >>> > RootCategory(Level.DEBUG));
 >>  >>> >  >>> >  >      loadLog4JConfig(config, hierarchy);
 >>  >>> >  >>> >  >      ClassLoader loader =
 >>  >>> >  >>> > Thread.currentThread().getContextClassLoader();
 >>  >>> >  >>> >  >      repositories.put(loader, hierarchy);
 >>  >>> >  >>> >  >   }
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >   public static synchronized void removeFromRepository()
 >> {
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >
 >>  >>> >
 >> repositories.remove(Thread.currentThread().getContextClassLoader());
 >>  >>> >  >>> >  >   }
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >   private static void loadLog4JConfig(ServletConfig
 >> config,
 >>  >>> >  >>> >  >                                       Hierarchy
 >> hierarchy)
 >>  >>> >  >>> >  >                                            throws
 >>  >>> > ServletException {
 >>  >>> >  >>> >  >        try {
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >               String strLogProperties =
 >>  >>> >  >>> >  >
 >>  >>> >  >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
 >>  >>> >  >>> >  >               System.out.println("strLogProperties: " +
 >>  >>> >  >>> > strLogProperties);
 >>  >>> >  >>> >  >               Properties logProperties = new
 >> Properties();
 >>  >>> >  >>> >  >               try {
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >
 >>  >>> >  >>>
 >>  >>> >
 >> >logProperties.load(config.getServletContext().getResourceAsStream(strL
 >>  >>> >  >>> >  >ogProperties));
 >>  >>> >  >>> >  >               } catch (Exception e) {
 >>  >>> >  >>> >  >                       System.out.println("ERROR: Loading
 >>  >>> log4j
 >>  >>> >  >>> > properties: " +
 >>  >>> >  >>> >  >e.getMessage());
 >>  >>> >  >>> >  >                       //e.printStackTrace();
 >>  >>> >  >>> >  >               }
 >>  >>> >  >>> >  >               PropertyConfigurator propConf = new
 >>  >>> >  >>> > PropertyConfigurator();
 >>  >>> >  >>> >  >            propConf.doConfigure(logProperties,
 >> hierarchy);
 >>  >>> >  >>> >  >                       } catch (Exception e) {
 >>  >>> >  >>> >  >            throw new ServletException(e);
 >>  >>> >  >>> >  >        }
 >>  >>> >  >>> >  >    }
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >   private MyRepositorySelector() {
 >>  >>> >  >>> >  >   }
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >   public LoggerRepository getLoggerRepository() {
 >>  >>> >  >>> >  >      ClassLoader loader =
 >>  >>> >  >>> > Thread.currentThread().getContextClassLoader();
 >>  >>> >  >>> >  >      LoggerRepository repository =
 >>  >>> >  >>> >  >(LoggerRepository)repositories.get(loader);
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >      if (repository == null) {
 >>  >>> >  >>> >  >          return defaultRepository;
 >>  >>> >  >>> >  >      } else {
 >>  >>> >  >>> >  >          return repository;
 >>  >>> >  >>> >  >      }
 >>  >>> >  >>> >  >   }
 >>  >>> >  >>> >  >}
 >>  >>> >  >>> >  >--
 >>  >>> >  >>> >  >View this message in context:
 >>  >>> >  >>> >
 >>  >>> >  >>>
 >>  >>> >
 >> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>  >>> >  >>> >
 >> >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
 >>  >>> >  >>> >  >Sent from the Log4j - Users mailing list archive at
 >>  >>> Nabble.com.
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >  >
 >>  >>> >  >>> >
 >>  >>> >
 >> >---------------------------------------------------------------------
 >>  >>> >  >>> >  >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 this message in context:
 >>  >>> >  >>>
 >>  >>> >  >>
 >>  >>> >
 >>  >>>
 >> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
 >>  >>> >  >>> Sent from the Log4j - Users mailing list archive at
 >> Nabble.com.
 >>  >>> >  >>>
 >>  >>> >  >>>
 >>  >>> >  >>>
 >>  >>> ---------------------------------------------------------------------
 >>  >>> >  >>> 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 this message in context:
 >>  >>> >
 >>  >>>
 >> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
 >>  >>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>  >>> >  >
 >>  >>> >  >
 >>  >>> >
 >> >---------------------------------------------------------------------
 >>  >>> >  >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 this message in context:
 >>  >>>
 >>  >>
 >>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
 >>  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>  >>>
 >>  >>>
 >>  >>> ---------------------------------------------------------------------
 >>  >>> 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 this message in context:
 >>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9969473
 >>  >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>  >
 >>  >
 >>  >---------------------------------------------------------------------
 >>  >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 this message in context:
 >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9987150
 >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >
 >
 >---------------------------------------------------------------------
 >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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by sohan <so...@mms.gov>.
Thanks Jake, Changing from Servlet to ServletContextListener helped,
accordingly I changed web.xml and applications are now logging to
independent log files. 

I have hit another block though with DailyRollingFileAppender, I changed one
applications properties to use DailyRollingFileAppender to roll over
everyminute for test purposes, If I understand correctly, rollover happens
if there is any logging to take place based on before and after the minute.
Instead my log file is just growing as if it is set to RollingFileAppender.
Restarted server few times too.
I have followed the properties example from chapter 3 from the manual, it
says the date pattern should be .yyyy-MM-dd-HH-mm. I tried both ways
.yyyy-MM-dd-HH-mm and '.'yyyy-MM-dd-HH-m but the log is not rolling over.
what is the correct syntax? ofcourse the manual is for 1.2.9 version and I
am using 1.2.8. What could be the reason for log file not rolling over. I am
running weblogic server on my local machine as myself with all the
privileges. Below is the properties listed.

Thanks for your patience and help,
Sohan

log4j.rootLogger=ERROR, FILE, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
%m%n
log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c:%L -
%m%n
log4j.logger.regs=DEBUG
log4j.logger.doc=DEBUG

#log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
log4j.appender.FILE.File=regs.log
log4j.appender.ROLL.DatePattern='.'yyyy-MM-dd-HH-mm
#log4j.appender.FILE.MaxFileSize=1MB
#log4j.appender.FILE.MaxBackupIndex=2



Jacob Kjome wrote:
> 
> At 05:13 PM 4/12/2007, you wrote:
>  >
>  >I have tried many ways to get this to work..partly successful but
> overall
>  >can't this to work. I even purchased the manual and reviewed it.
>  >
>  >Tried Log4j 1.3, It was like opening a can of worms..weblogic 8.1.6
> internal
>  >logging complained, had to revert back to Log4j 1.2 version.
>  >
> 
> That's too bad.  Of course this is why there will most likely never 
> be an official release of 1.3.  It's currently too incompatible with
> 1.2.xx.
> 
>  >Earlier I was able to log only class files extending Httpservlet which
> were
>  >identified in web.xml file with load-on-startup values set to 1 and 2.
>  >Looking closely at weblogic startup script, found a configuration file
> being
>  >set there for weblogic workshop with -Dlog4j.configuration property,
> once I
>  >commented this out, I was able to log from other class files of the
>  >application however "filter" class files are not being logged, Based on
>  >System.out.... statements, console shows that these filter classes are
> being
>  >loaded even before the servlet object initializing log4j
> RepositorySelector
>  >with load-on-startup set to 1 is loaded  At this point I am not getting
>  >default log4j.log file either. Basically, my filter log is lost. Tried
>  >getLogger("pcs") based on logger configuration in properties file,
> didn't
>  >get any errors not logging.
>  >
> 
> Why in the world are you using a Servlet to perform Log4j 
> initialization?  That's what a ServletContextListener is for, and it 
> will certainly be loaded before any other webapp resources get 
> loaded, such as servlets or filters.  And if that fails, you can 
> always write a Weblogic startup class (see the Weblogic docs) that 
> installs the repository selector at Weblogic startup time, before any 
> apps get loaded.
> 
> And why don't you lower the level of your root logger in the 
> configuration to be DEBUG instead of ERROR?  Not permanently, just 
> until you verify that you are getting logging output, at which point 
> you can set it back.
> 
>  >I made similar changes to my second application, basically copied the
>  >MyRepositorySelector.java file changed the Log4jinit.java file to set
>  >RepositorySelector and Log4j.properties file or Log4j.xml file are
> similar
>  >with exception of the "log4j.appender.FILE.File", "log4j.logger.regs"
>  >entries, in bold below. Configuration file names are the same.
>  >In this case both log files are being created, however, the application
> that
>  >is loaded last during startup, only that application's log is being
> created.
>  >First application's log is not being written after initialization
> entries,
>  >unless second application is either removed or changes related to
>  >RepositorySelector are reverted.
>  >
> 
> Probably an issue with using a classloader-based repository selector 
> rather than a JNDI-based one.
> 
>  >log4j.rootLogger=ERROR, FILE, CONSOLE
>  >log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
>  >log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
>  >%m%n
>  >log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
> %m%n
>  >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p
> %c:%L -
>  >%m%n
>  >log4j.logger.regs=DEBUG
>  >log4j.logger.doc=DEBUG
>  >log4j.appender.FILE=org.apache.log4j.RollingFileAppender
>  >log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
>  >log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l -
> %m%n
>  >log4j.appender.FILE.File=regs.log
>  >log4j.appender.FILE.MaxFileSize=1MB
>  >log4j.appender.FILE.MaxBackupIndex=2
>  >
>  >After 3 days, At this point I am not sure if I can get this to work!
>  >
> 
> I know how frustrating it can be.  But did you try the 
> ContextJNDISelector from the Log4j sandbox?  It is 1.2 compatible.  I 
> can't promise you it will work in Weblogic because I haven't tried it 
> with that server, but it's worth a shot.  Here's the link again....
> 
> http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
> 
> 
> Jake
> 
>  >thanks,
>  >Sohan
>  >
>  >
>  >
>  >Jacob Kjome wrote:
>  >>
>  >>
>  >> Looks mostly correct.  You could change jakarta.apache.org or
>  >> logging.apache.org, but that's inconsequential.  Also, you should
> apply a
>  >> level
>  >> to the root logger, such as <level value="WARN"/>, or maybe set it to
>  >> DEBUG for
>  >> testing.
>  >>
>  >> See the Log4j Wiki [1] for links to WizardForge (look at the bottom of
> the
>  >> page), which will walk you through the steps of generating valid Log4j
> 1.2
>  >> and
>  >> 1.3 compatible config files.
>  >>
>  >> Just to be clear, I'm not advocating moving to Log4j 1.3, as it may
> never
>  >> be
>  >> fully released outside of alpha builds.  I just want to to try it out
>  >> since it
>  >> currently has a working JNDIContextSelector that you can use to test
>  >> against.
>  >> It's a selector that I know, at least in my testing, works.  If you
> find
>  >> it to
>  >> work for you, you can adapt it to create your own selector which would
> be
>  >> compatible with Log4j 1.2.  I also forgot to mention that I created a
>  >> Log4j-1.2
>  >> compatible ContextJNDISelector in the log4j sandbox [2].  It works
>  >> slightly
>  >> differently than the one in Log4j-1.3, but it might provide a good
> base
>  >> for you
>  >> to start from.
>  >>
>  >> [1] http://wiki.apache.org/logging-log4j/Log4JProjectPages
>  >> [2]
>  >>
>  >http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/
>  >LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
>  >>
>  >>
>  >> Jake
>  >>
>  >> Quoting sohan <so...@mms.gov>:
>  >>
>  >>>
>  >>> Hi jake,
>  >>>
>  >>> Before I start using Log4j-1.3, I want to confirm if my Log4j.xml is
>  >>> valid
>  >>> for my requirements
>  >>> Below is the xml..I removed SYSTEM entry as I was getting log4j.dtd
> file
>  >>> not
>  >>> found error during weblogic startup.
>  >>> In this xml do I need to specify logger entry? Am I missing anything!
>  >>>
>  >>> thanks,
>  >>> Sohan
>  >>>
>  >>> <?xml version="1.0" encoding="UTF-8"?>
>  >>> <!DOCTYPE log4j:configuration >
>  >>>
>  >>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>  >>> debug="false">
>  >>>
>  >>>    <!-- A time/date based rolling appender -->
>  >>>    <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log -->
>  >>>    <!-- <appender name="TEST"
>  >>> class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
>  >>>    <appender name="TEST"
> class="org.apache.log4j.RollingFileAppender">
>  >>>       <!-- <errorHandler
>  >>> class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
>  >>>       <param name="File" value="pcs.log"/>
>  >>>       <param name="Append" value="false"/>
>  >>>
>  >>>       <!-- Rollover at midnight each day -->
>  >>>        <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->
>  >>>
>  >>>       <layout class="org.apache.log4j.PatternLayout">
>  >>>          <!-- The default pattern: Date Priority [Category] Message\n
> -->
>  >>>          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
>  >>>
>  >>>          <!-- The full pattern: Date MS Priority [Category]
> (Thread:NDC)
>  >>> Message\n
>  >>>          <param name="ConversionPattern" value="%d %-5r %-5p [%c]
> (%t:%x)
>  >>> %m%n"/>
>  >>>           -->
>  >>>       </layout>
>  >>>    </appender>
>  >>>
>  >>>    <!-- ======================= -->
>  >>>    <!-- Setup the Root category -->
>  >>>    <!-- ======================= -->
>  >>>
>  >>>    <root>
>  >>>       <appender-ref ref="TEST"/>
>  >>>    </root>
>  >>>
>  >>> </log4j:configuration>
>  >>>
>  >>>
>  >>> Jacob Kjome wrote:
>  >>> >
>  >>> >
>  >>> > Have you tried using the JNDI repository selector solution, such as
>  >>> > in Log4j-1.3?  To test this out quickly, you could just try using
>  >>> > Log4j-1.3 and its ContextJNDISelector class to perform the
> repository
>  >>> > selection.  I know it works.  I'm not sure why you are seeing odd
>  >>> > results with the classloader-based selector you wrote, but I
> haven't
>  >>> > gone over the code intensively either.  In any case, don't use a
>  >>> > classloader-based approach.  It will give you nothing but
> headaches,
>  >>> > in my experience.
>  >>> >
>  >>> > Add the following to your server startup script...
>  >>> >
>  >>> > -Dlog4j.repositorySelector=JNDI
>  >>> >
>  >>> >
>  >>> > Add the following to your web.xml....
>  >>> >
>  >>> >      <listener>
>  >>> >          <!-- this feature may require building Log4j-1.3 from
>  >>> > source, as it may not be in the latest released alpha jar??? -->
>  >>> >
>  >>> >
>  >>>
>  >>
>  ><listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL<
>  >/listener-class>
>  >>> >      </listener>
>  >>> >
>  >>> >      <env-entry>
>  >>> >          <description>JNDI logging context for this
> app</description>
>  >>> >          <env-entry-name>log4j/context-name</env-entry-name>
>  >>> >          <env-entry-value>myapp</env-entry-value>
>  >>> >          <env-entry-type>java.lang.String</env-entry-type>
>  >>> >      </env-entry>
>  >>> >
>  >>> >      <env-entry>
>  >>> >          <description>URL for configuring log4j
> context</description>
>  >>> >         
> <env-entry-name>log4j/configuration-resource</env-entry-name>
>  >>> >          <env-entry-value>myapp-log4j.xml</env-entry-value>
>  >>> >          <env-entry-type>java.lang.String</env-entry-type>
>  >>> >      </env-entry>
>  >>> >
>  >>> >
>  >>> > Jake
>  >>> >
>  >>> > At 07:08 PM 4/10/2007, you wrote:
>  >>> >  >
>  >>> >  >"What do you mean "'pcs' is the log file name"?  That would be
> the
>  >>> > logger
>  >>> >  >name,
>  >>> >  >not the file name."
>  >>> >  >My mistake, I meant to say that it is both the logger name as
> well as
>  >>> I
>  >>> >  >named the log file name same too after the application name.
>  >>> >  > I tried with both LogFactory of commons-logging as well as
> direct
>  >>> use
>  >>> > of
>  >>> >  >Log4j. Behavior is the same
>  >>> >  >I did notice one thing, Log information is being written normally
>  >>> from
>  >>> > java
>  >>> >  >classes that extend HttpServlet.
>  >>> >  >Logging from other java class files is not working as intended.
> My
>  >>> >  >application uses struts 1.2.9 too.
>  >>> >  >
>  >>> >  >thanks,
>  >>> >  >Sohan
>  >>> >  >
>  >>> >  >
>  >>> >  >Jacob Kjome wrote:
>  >>> >  >>
>  >>> >  >> Quoting sohan <so...@mms.gov>:
>  >>> >  >>
>  >>> >  >>>
>  >>> >  >>> I changed to use Log4j.xml from Log4j.properties and also
> changed
>  >>> to
>  >>> >  >>> non-static loggers and with in the static methods followed the
>  >>> link
>  >>> >  >>> examples. Now the logging is taking place only for the loggers
>  >>> > mentioned
>  >>> >  >>> in
>  >>> >  >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is
> the
>  >>> > log
>  >>> >  >>> file
>  >>> >  >>> name.
>  >>> >  >>>
>  >>> >  >>
>  >>> >  >> What do you mean "'pcs' is the log file name"?  That would be
> the
>  >>> > logger
>  >>> >  >> name,
>  >>> >  >> not the file name.
>  >>> >  >>
>  >>> >  >> Also, I didn't mean to direct you to use commons-logging.  If
> you
>  >>> were
>  >>> >  >> using
>  >>> >  >> log4j directly, please keep using it.  In fact, log wrappers
> like
>  >>> > SLF4J
>  >>> >  >> and
>  >>> >  >> commons-logging have issues when it comes to repository
> selectors.
>  >>> > Search
>  >>> >  >> the
>  >>> >  >> SLF4J user list for details on this.  There's also a bug in the
>  >>> SLF4J
>  >>> >  >> database
>  >>> >  >> about this.  I believe the same applies to commons-logging. 
> Log4j
>  >>> > cannot
>  >>> >  >> guarantee proper logging separation when you use a wrapper.
>  >>> >  >>
>  >>> >  >>> Any idea as to why the non static logger is not working!
>  >>> >  >>>
>  >>> >  >>
>  >>> >  >> I would guess it's because you are using commons-logging.  Use
>  >>> Log4j
>  >>> >  >> directly,
>  >>> >  >> just as you were previously.  I only sent you the
> commons-logging
>  >>> link
>  >>> >  >> because
>  >>> >  >> they had a good synopsis of the static logger issue, not to
>  >>> convince
>  >>> > you
>  >>> >  >> to
>  >>> >  >> move to commons-logging.
>  >>> >  >>
>  >>> >  >>
>  >>> >  >> Jake
>  >>> >  >>
>  >>> >  >>> thanks,
>  >>> >  >>> Sohan
>  >>> >  >>>
>  >>> >  >>>
>  >>> >  >>> Jacob Kjome wrote:
>  >>> >  >>> >
>  >>> >  >>> >
>  >>> >  >>> > 1.  Use non-static loggers (for Serializable classes, you'll
>  >>> need
>  >>> > to
>  >>> >  >>> > mark these as transient)
>  >>> >  >>> > 2.  Avoid Classloader-based repository selectors.  Use
> JNDI-base
>  >>> >  >>> > selectors.  There's already one written for Log4j-1.3alpha.
>  >>> Even
>  >>> > if
>  >>> >  >>> > you don't care to use 1.3, you can use it to get an idea of
> how
>  >>> to
>  >>> >  >>> > write one for 1.2.
>  >>> >  >>> >
>  >>> >  >>> >
>  >>> >  >>> > See:
>  >>> >  >>> > http://www.qos.ch/logging/sc.jsp
>  >>> >  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>  >>> >  >>> >
>  >>> >  >>> >
>  >>> >  >>> > Jake
>  >>> >  >>> >
>  >>> >  >>> > At 03:09 PM 4/9/2007, you wrote:
>  >>> >  >>> >  >
>  >>> >  >>> >  >I followed some examples on the web to use
> RepositorySelector
>  >>> to
>  >>> >  >>> > implement
>  >>> >  >>> >  >separate logging for 2 applications deployed on the same
>  >>> instance
>  >>> > of
>  >>> >  >>> >  >weblogic server. I have the Lgo4j.properties file under
>  >>> Web-Inf/
>  >>> >  >>> folder,
>  >>> >  >>> >  >This is loaded through web.xml file through a startup
> servlet.
>  >>> >  >>> Problem
>  >>> >  >>> > is
>  >>> >  >>> >  >logging is taking place either in Log4j.log file or other
>  >>> >  >>> applications
>  >>> >  >>> > log
>  >>> >  >>> >  >file. In each java class file, I use..
>  >>> >  >>> >  >       private static Logger log =
>  >>> >  >>> Logger.getLogger(LoginFilter.class);
>  >>> >  >>> >  >and call the log .info ..accordingly. In log4j properties
>  >>> file,
>  >>> > only
>  >>> >  >>> >  >difference is file name for 2 applications.
>  >>> >  >>> >  >
>  >>> >  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
>  >>> >  >>> >  >
>  >>> >  >>> >  >thanks for the help
>  >>> >  >>> >  >Sohan
>  >>> >  >>> >  >
>  >>> >  >>> >  >web.xml entry...
>  >>> >  >>> >  >
>  >>> >  >>> >  >       <servlet>
>  >>> >  >>> >  >               <servlet-name>log4j-init</servlet-name>
>  >>> >  >>> >  >
>  >>> >  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
>  >>> >  >>> >  >           <init-param>
>  >>> >  >>> >  >                  
> <param-name>Log4JProperties</param-name>
>  >>> >  >>> >  >
>  >>> >  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
>  >>> >  >>> >  >           </init-param>
>  >>> >  >>> >  >           <init-param>
>  >>> >  >>> >  >                   <param-name>LogToFileOnly</param-name>
>  >>> >  >>> >  >                   <param-value>false</param-value>
>  >>> >  >>> >  >           </init-param>
>  >>> >  >>> >  >               <load-on-startup>1</load-on-startup>
>  >>> >  >>> >  >       </servlet>
>  >>> >  >>> >  >
>  >>> >  >>> >  >public class Log4jInit extends HttpServlet {
>  >>> >  >>> >  >       static Logger log =
> Logger.getLogger(Log4jInit.class);
>  >>> >  >>> >  >       public void init() throws ServletException {
>  >>> >  >>> >  >
>  >>> >  >>> >
>  >>> >
> System.out.println("\n\n---------------Log4jInit---------------\n\n");
>  >>> >  >>> >
>  >>> >  >>> >  >
>  >>> > MyRepositorySelector.init(this.getServletConfig());
>  >>> >  >>> >  >               Logger log =
> Logger.getLogger(this.getClass());
>  >>> >  >>> >  >               log.info("Log message from Log4jInit
> servlet");
>  >>> >  >>> >  >
>  >>> System.out.println("\n\n---------------Log4jInit:
>  >>> >  >>> >  >Complete---------------\n\n");
>  >>> >  >>> >  >
>  >>> >  >>> >  >       }
>  >>> >  >>> >  >
>  >>> >  >>> >  >}
>  >>> >  >>> >  >
>  >>> >  >>> >  >public class MyRepositorySelector implements
>  >>> RepositorySelector
>  >>> >  >>> >  >{
>  >>> >  >>> >  >   private static boolean initialized = false;
>  >>> >  >>> >  >   private static Object guard =
> LogManager.getRootLogger();
>  >>> >  >>> >  >
>  >>> >  >>> >  >   private static Map repositories = new HashMap();
>  >>> >  >>> >  >   private static LoggerRepository defaultRepository;
>  >>> >  >>> >  >
>  >>> >  >>> >  >   public static synchronized void init(ServletConfig
> config)
>  >>> >  >>> >  >        throws ServletException {
>  >>> >  >>> >  >      if( !initialized ) // set the global
> RepositorySelector
>  >>> >  >>> >  >      {
>  >>> >  >>> >  >         defaultRepository =
> LogManager.getLoggerRepository();
>  >>> >  >>> >  >         RepositorySelector theSelector = new
>  >>> > MyRepositorySelector();
>  >>> >  >>> >  >         LogManager.setRepositorySelector(theSelector,
> guard);
>  >>> >  >>> >  >         initialized = true;
>  >>> >  >>> >  >      }
>  >>> >  >>> >  >
>  >>> >  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
>  >>> >  >>> > RootCategory(Level.DEBUG));
>  >>> >  >>> >  >      loadLog4JConfig(config, hierarchy);
>  >>> >  >>> >  >      ClassLoader loader =
>  >>> >  >>> > Thread.currentThread().getContextClassLoader();
>  >>> >  >>> >  >      repositories.put(loader, hierarchy);
>  >>> >  >>> >  >   }
>  >>> >  >>> >  >
>  >>> >  >>> >  >   public static synchronized void removeFromRepository()
> {
>  >>> >  >>> >  >
>  >>> >  >>> >
>  >>> >
> repositories.remove(Thread.currentThread().getContextClassLoader());
>  >>> >  >>> >  >   }
>  >>> >  >>> >  >
>  >>> >  >>> >  >
>  >>> >  >>> >  >   private static void loadLog4JConfig(ServletConfig
> config,
>  >>> >  >>> >  >                                       Hierarchy
> hierarchy)
>  >>> >  >>> >  >                                            throws
>  >>> > ServletException {
>  >>> >  >>> >  >        try {
>  >>> >  >>> >  >
>  >>> >  >>> >  >               String strLogProperties =
>  >>> >  >>> >  >
>  >>> >  >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
>  >>> >  >>> >  >               System.out.println("strLogProperties: " +
>  >>> >  >>> > strLogProperties);
>  >>> >  >>> >  >               Properties logProperties = new
> Properties();
>  >>> >  >>> >  >               try {
>  >>> >  >>> >  >
>  >>> >  >>> >
>  >>> >  >>>
>  >>> >
> >logProperties.load(config.getServletContext().getResourceAsStream(strL
>  >>> >  >>> >  >ogProperties));
>  >>> >  >>> >  >               } catch (Exception e) {
>  >>> >  >>> >  >                       System.out.println("ERROR: Loading
>  >>> log4j
>  >>> >  >>> > properties: " +
>  >>> >  >>> >  >e.getMessage());
>  >>> >  >>> >  >                       //e.printStackTrace();
>  >>> >  >>> >  >               }
>  >>> >  >>> >  >               PropertyConfigurator propConf = new
>  >>> >  >>> > PropertyConfigurator();
>  >>> >  >>> >  >            propConf.doConfigure(logProperties,
> hierarchy);
>  >>> >  >>> >  >                       } catch (Exception e) {
>  >>> >  >>> >  >            throw new ServletException(e);
>  >>> >  >>> >  >        }
>  >>> >  >>> >  >    }
>  >>> >  >>> >  >
>  >>> >  >>> >  >   private MyRepositorySelector() {
>  >>> >  >>> >  >   }
>  >>> >  >>> >  >
>  >>> >  >>> >  >   public LoggerRepository getLoggerRepository() {
>  >>> >  >>> >  >      ClassLoader loader =
>  >>> >  >>> > Thread.currentThread().getContextClassLoader();
>  >>> >  >>> >  >      LoggerRepository repository =
>  >>> >  >>> >  >(LoggerRepository)repositories.get(loader);
>  >>> >  >>> >  >
>  >>> >  >>> >  >      if (repository == null) {
>  >>> >  >>> >  >          return defaultRepository;
>  >>> >  >>> >  >      } else {
>  >>> >  >>> >  >          return repository;
>  >>> >  >>> >  >      }
>  >>> >  >>> >  >   }
>  >>> >  >>> >  >}
>  >>> >  >>> >  >--
>  >>> >  >>> >  >View this message in context:
>  >>> >  >>> >
>  >>> >  >>>
>  >>> >
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>> >  >>> > 
> >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
>  >>> >  >>> >  >Sent from the Log4j - Users mailing list archive at
>  >>> Nabble.com.
>  >>> >  >>> >  >
>  >>> >  >>> >  >
>  >>> >  >>> >
>  >>> >
> >---------------------------------------------------------------------
>  >>> >  >>> >  >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 this message in context:
>  >>> >  >>>
>  >>> >  >>
>  >>> >
>  >>>
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
>  >>> >  >>> Sent from the Log4j - Users mailing list archive at
> Nabble.com.
>  >>> >  >>>
>  >>> >  >>>
>  >>> >  >>>
>  >>> ---------------------------------------------------------------------
>  >>> >  >>> 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 this message in context:
>  >>> >
>  >>>
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
>  >>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >>> >  >
>  >>> >  >
>  >>> > 
> >---------------------------------------------------------------------
>  >>> >  >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 this message in context:
>  >>>
>  >>
>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
>  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >>>
>  >>>
>  >>> ---------------------------------------------------------------------
>  >>> 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 this message in context:
>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9969473
>  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >
>  >
>  >---------------------------------------------------------------------
>  >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 this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9987150
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by Jacob Kjome <ho...@visi.com>.
At 05:13 PM 4/12/2007, you wrote:
 >
 >I have tried many ways to get this to work..partly successful but overall
 >can't this to work. I even purchased the manual and reviewed it.
 >
 >Tried Log4j 1.3, It was like opening a can of worms..weblogic 8.1.6 internal
 >logging complained, had to revert back to Log4j 1.2 version.
 >

That's too bad.  Of course this is why there will most likely never 
be an official release of 1.3.  It's currently too incompatible with 1.2.xx.

 >Earlier I was able to log only class files extending Httpservlet which were
 >identified in web.xml file with load-on-startup values set to 1 and 2.
 >Looking closely at weblogic startup script, found a configuration file being
 >set there for weblogic workshop with -Dlog4j.configuration property, once I
 >commented this out, I was able to log from other class files of the
 >application however "filter" class files are not being logged, Based on
 >System.out.... statements, console shows that these filter classes are being
 >loaded even before the servlet object initializing log4j RepositorySelector
 >with load-on-startup set to 1 is loaded  At this point I am not getting
 >default log4j.log file either. Basically, my filter log is lost. Tried
 >getLogger("pcs") based on logger configuration in properties file, didn't
 >get any errors not logging.
 >

Why in the world are you using a Servlet to perform Log4j 
initialization?  That's what a ServletContextListener is for, and it 
will certainly be loaded before any other webapp resources get 
loaded, such as servlets or filters.  And if that fails, you can 
always write a Weblogic startup class (see the Weblogic docs) that 
installs the repository selector at Weblogic startup time, before any 
apps get loaded.

And why don't you lower the level of your root logger in the 
configuration to be DEBUG instead of ERROR?  Not permanently, just 
until you verify that you are getting logging output, at which point 
you can set it back.

 >I made similar changes to my second application, basically copied the
 >MyRepositorySelector.java file changed the Log4jinit.java file to set
 >RepositorySelector and Log4j.properties file or Log4j.xml file are similar
 >with exception of the "log4j.appender.FILE.File", "log4j.logger.regs"
 >entries, in bold below. Configuration file names are the same.
 >In this case both log files are being created, however, the application that
 >is loaded last during startup, only that application's log is being created.
 >First application's log is not being written after initialization entries,
 >unless second application is either removed or changes related to
 >RepositorySelector are reverted.
 >

Probably an issue with using a classloader-based repository selector 
rather than a JNDI-based one.

 >log4j.rootLogger=ERROR, FILE, CONSOLE
 >log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
 >log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
 >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
 >%m%n
 >log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
 >#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c:%L -
 >%m%n
 >log4j.logger.regs=DEBUG
 >log4j.logger.doc=DEBUG
 >log4j.appender.FILE=org.apache.log4j.RollingFileAppender
 >log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 >log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
 >log4j.appender.FILE.File=regs.log
 >log4j.appender.FILE.MaxFileSize=1MB
 >log4j.appender.FILE.MaxBackupIndex=2
 >
 >After 3 days, At this point I am not sure if I can get this to work!
 >

I know how frustrating it can be.  But did you try the 
ContextJNDISelector from the Log4j sandbox?  It is 1.2 compatible.  I 
can't promise you it will work in Weblogic because I haven't tried it 
with that server, but it's worth a shot.  Here's the link again....

http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/


Jake

 >thanks,
 >Sohan
 >
 >
 >
 >Jacob Kjome wrote:
 >>
 >>
 >> Looks mostly correct.  You could change jakarta.apache.org or
 >> logging.apache.org, but that's inconsequential.  Also, you should apply a
 >> level
 >> to the root logger, such as <level value="WARN"/>, or maybe set it to
 >> DEBUG for
 >> testing.
 >>
 >> See the Log4j Wiki [1] for links to WizardForge (look at the bottom of the
 >> page), which will walk you through the steps of generating valid Log4j 1.2
 >> and
 >> 1.3 compatible config files.
 >>
 >> Just to be clear, I'm not advocating moving to Log4j 1.3, as it may never
 >> be
 >> fully released outside of alpha builds.  I just want to to try it out
 >> since it
 >> currently has a working JNDIContextSelector that you can use to test
 >> against.
 >> It's a selector that I know, at least in my testing, works.  If you find
 >> it to
 >> work for you, you can adapt it to create your own selector which would be
 >> compatible with Log4j 1.2.  I also forgot to mention that I created a
 >> Log4j-1.2
 >> compatible ContextJNDISelector in the log4j sandbox [2].  It works
 >> slightly
 >> differently than the one in Log4j-1.3, but it might provide a good base
 >> for you
 >> to start from.
 >>
 >> [1] http://wiki.apache.org/logging-log4j/Log4JProjectPages
 >> [2]
 >>
 >http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/
 >LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
 >>
 >>
 >> Jake
 >>
 >> Quoting sohan <so...@mms.gov>:
 >>
 >>>
 >>> Hi jake,
 >>>
 >>> Before I start using Log4j-1.3, I want to confirm if my Log4j.xml is
 >>> valid
 >>> for my requirements
 >>> Below is the xml..I removed SYSTEM entry as I was getting log4j.dtd file
 >>> not
 >>> found error during weblogic startup.
 >>> In this xml do I need to specify logger entry? Am I missing anything!
 >>>
 >>> thanks,
 >>> Sohan
 >>>
 >>> <?xml version="1.0" encoding="UTF-8"?>
 >>> <!DOCTYPE log4j:configuration >
 >>>
 >>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
 >>> debug="false">
 >>>
 >>>    <!-- A time/date based rolling appender -->
 >>>    <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log -->
 >>>    <!-- <appender name="TEST"
 >>> class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
 >>>    <appender name="TEST" class="org.apache.log4j.RollingFileAppender">
 >>>       <!-- <errorHandler
 >>> class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
 >>>       <param name="File" value="pcs.log"/>
 >>>       <param name="Append" value="false"/>
 >>>
 >>>       <!-- Rollover at midnight each day -->
 >>>        <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->
 >>>
 >>>       <layout class="org.apache.log4j.PatternLayout">
 >>>          <!-- The default pattern: Date Priority [Category] Message\n -->
 >>>          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
 >>>
 >>>          <!-- The full pattern: Date MS Priority [Category] (Thread:NDC)
 >>> Message\n
 >>>          <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
 >>> %m%n"/>
 >>>           -->
 >>>       </layout>
 >>>    </appender>
 >>>
 >>>    <!-- ======================= -->
 >>>    <!-- Setup the Root category -->
 >>>    <!-- ======================= -->
 >>>
 >>>    <root>
 >>>       <appender-ref ref="TEST"/>
 >>>    </root>
 >>>
 >>> </log4j:configuration>
 >>>
 >>>
 >>> Jacob Kjome wrote:
 >>> >
 >>> >
 >>> > Have you tried using the JNDI repository selector solution, such as
 >>> > in Log4j-1.3?  To test this out quickly, you could just try using
 >>> > Log4j-1.3 and its ContextJNDISelector class to perform the repository
 >>> > selection.  I know it works.  I'm not sure why you are seeing odd
 >>> > results with the classloader-based selector you wrote, but I haven't
 >>> > gone over the code intensively either.  In any case, don't use a
 >>> > classloader-based approach.  It will give you nothing but headaches,
 >>> > in my experience.
 >>> >
 >>> > Add the following to your server startup script...
 >>> >
 >>> > -Dlog4j.repositorySelector=JNDI
 >>> >
 >>> >
 >>> > Add the following to your web.xml....
 >>> >
 >>> >      <listener>
 >>> >          <!-- this feature may require building Log4j-1.3 from
 >>> > source, as it may not be in the latest released alpha jar??? -->
 >>> >
 >>> >
 >>>
 >>
 ><listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL<
 >/listener-class>
 >>> >      </listener>
 >>> >
 >>> >      <env-entry>
 >>> >          <description>JNDI logging context for this app</description>
 >>> >          <env-entry-name>log4j/context-name</env-entry-name>
 >>> >          <env-entry-value>myapp</env-entry-value>
 >>> >          <env-entry-type>java.lang.String</env-entry-type>
 >>> >      </env-entry>
 >>> >
 >>> >      <env-entry>
 >>> >          <description>URL for configuring log4j context</description>
 >>> >          <env-entry-name>log4j/configuration-resource</env-entry-name>
 >>> >          <env-entry-value>myapp-log4j.xml</env-entry-value>
 >>> >          <env-entry-type>java.lang.String</env-entry-type>
 >>> >      </env-entry>
 >>> >
 >>> >
 >>> > Jake
 >>> >
 >>> > At 07:08 PM 4/10/2007, you wrote:
 >>> >  >
 >>> >  >"What do you mean "'pcs' is the log file name"?  That would be the
 >>> > logger
 >>> >  >name,
 >>> >  >not the file name."
 >>> >  >My mistake, I meant to say that it is both the logger name as well as
 >>> I
 >>> >  >named the log file name same too after the application name.
 >>> >  > I tried with both LogFactory of commons-logging as well as direct
 >>> use
 >>> > of
 >>> >  >Log4j. Behavior is the same
 >>> >  >I did notice one thing, Log information is being written normally
 >>> from
 >>> > java
 >>> >  >classes that extend HttpServlet.
 >>> >  >Logging from other java class files is not working as intended. My
 >>> >  >application uses struts 1.2.9 too.
 >>> >  >
 >>> >  >thanks,
 >>> >  >Sohan
 >>> >  >
 >>> >  >
 >>> >  >Jacob Kjome wrote:
 >>> >  >>
 >>> >  >> Quoting sohan <so...@mms.gov>:
 >>> >  >>
 >>> >  >>>
 >>> >  >>> I changed to use Log4j.xml from Log4j.properties and also changed
 >>> to
 >>> >  >>> non-static loggers and with in the static methods followed the
 >>> link
 >>> >  >>> examples. Now the logging is taking place only for the loggers
 >>> > mentioned
 >>> >  >>> in
 >>> >  >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the
 >>> > log
 >>> >  >>> file
 >>> >  >>> name.
 >>> >  >>>
 >>> >  >>
 >>> >  >> What do you mean "'pcs' is the log file name"?  That would be the
 >>> > logger
 >>> >  >> name,
 >>> >  >> not the file name.
 >>> >  >>
 >>> >  >> Also, I didn't mean to direct you to use commons-logging.  If you
 >>> were
 >>> >  >> using
 >>> >  >> log4j directly, please keep using it.  In fact, log wrappers like
 >>> > SLF4J
 >>> >  >> and
 >>> >  >> commons-logging have issues when it comes to repository selectors.
 >>> > Search
 >>> >  >> the
 >>> >  >> SLF4J user list for details on this.  There's also a bug in the
 >>> SLF4J
 >>> >  >> database
 >>> >  >> about this.  I believe the same applies to commons-logging.  Log4j
 >>> > cannot
 >>> >  >> guarantee proper logging separation when you use a wrapper.
 >>> >  >>
 >>> >  >>> Any idea as to why the non static logger is not working!
 >>> >  >>>
 >>> >  >>
 >>> >  >> I would guess it's because you are using commons-logging.  Use
 >>> Log4j
 >>> >  >> directly,
 >>> >  >> just as you were previously.  I only sent you the commons-logging
 >>> link
 >>> >  >> because
 >>> >  >> they had a good synopsis of the static logger issue, not to
 >>> convince
 >>> > you
 >>> >  >> to
 >>> >  >> move to commons-logging.
 >>> >  >>
 >>> >  >>
 >>> >  >> Jake
 >>> >  >>
 >>> >  >>> thanks,
 >>> >  >>> Sohan
 >>> >  >>>
 >>> >  >>>
 >>> >  >>> Jacob Kjome wrote:
 >>> >  >>> >
 >>> >  >>> >
 >>> >  >>> > 1.  Use non-static loggers (for Serializable classes, you'll
 >>> need
 >>> > to
 >>> >  >>> > mark these as transient)
 >>> >  >>> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
 >>> >  >>> > selectors.  There's already one written for Log4j-1.3alpha.
 >>> Even
 >>> > if
 >>> >  >>> > you don't care to use 1.3, you can use it to get an idea of how
 >>> to
 >>> >  >>> > write one for 1.2.
 >>> >  >>> >
 >>> >  >>> >
 >>> >  >>> > See:
 >>> >  >>> > http://www.qos.ch/logging/sc.jsp
 >>> >  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
 >>> >  >>> >
 >>> >  >>> >
 >>> >  >>> > Jake
 >>> >  >>> >
 >>> >  >>> > At 03:09 PM 4/9/2007, you wrote:
 >>> >  >>> >  >
 >>> >  >>> >  >I followed some examples on the web to use RepositorySelector
 >>> to
 >>> >  >>> > implement
 >>> >  >>> >  >separate logging for 2 applications deployed on the same
 >>> instance
 >>> > of
 >>> >  >>> >  >weblogic server. I have the Lgo4j.properties file under
 >>> Web-Inf/
 >>> >  >>> folder,
 >>> >  >>> >  >This is loaded through web.xml file through a startup servlet.
 >>> >  >>> Problem
 >>> >  >>> > is
 >>> >  >>> >  >logging is taking place either in Log4j.log file or other
 >>> >  >>> applications
 >>> >  >>> > log
 >>> >  >>> >  >file. In each java class file, I use..
 >>> >  >>> >  >       private static Logger log =
 >>> >  >>> Logger.getLogger(LoginFilter.class);
 >>> >  >>> >  >and call the log .info ..accordingly. In log4j properties
 >>> file,
 >>> > only
 >>> >  >>> >  >difference is file name for 2 applications.
 >>> >  >>> >  >
 >>> >  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
 >>> >  >>> >  >
 >>> >  >>> >  >thanks for the help
 >>> >  >>> >  >Sohan
 >>> >  >>> >  >
 >>> >  >>> >  >web.xml entry...
 >>> >  >>> >  >
 >>> >  >>> >  >       <servlet>
 >>> >  >>> >  >               <servlet-name>log4j-init</servlet-name>
 >>> >  >>> >  >
 >>> >  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
 >>> >  >>> >  >           <init-param>
 >>> >  >>> >  >                   <param-name>Log4JProperties</param-name>
 >>> >  >>> >  >
 >>> >  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
 >>> >  >>> >  >           </init-param>
 >>> >  >>> >  >           <init-param>
 >>> >  >>> >  >                   <param-name>LogToFileOnly</param-name>
 >>> >  >>> >  >                   <param-value>false</param-value>
 >>> >  >>> >  >           </init-param>
 >>> >  >>> >  >               <load-on-startup>1</load-on-startup>
 >>> >  >>> >  >       </servlet>
 >>> >  >>> >  >
 >>> >  >>> >  >public class Log4jInit extends HttpServlet {
 >>> >  >>> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
 >>> >  >>> >  >       public void init() throws ServletException {
 >>> >  >>> >  >
 >>> >  >>> >
 >>> > System.out.println("\n\n---------------Log4jInit---------------\n\n");
 >>> >  >>> >
 >>> >  >>> >  >
 >>> > MyRepositorySelector.init(this.getServletConfig());
 >>> >  >>> >  >               Logger log = Logger.getLogger(this.getClass());
 >>> >  >>> >  >               log.info("Log message from Log4jInit servlet");
 >>> >  >>> >  >
 >>> System.out.println("\n\n---------------Log4jInit:
 >>> >  >>> >  >Complete---------------\n\n");
 >>> >  >>> >  >
 >>> >  >>> >  >       }
 >>> >  >>> >  >
 >>> >  >>> >  >}
 >>> >  >>> >  >
 >>> >  >>> >  >public class MyRepositorySelector implements
 >>> RepositorySelector
 >>> >  >>> >  >{
 >>> >  >>> >  >   private static boolean initialized = false;
 >>> >  >>> >  >   private static Object guard = LogManager.getRootLogger();
 >>> >  >>> >  >
 >>> >  >>> >  >   private static Map repositories = new HashMap();
 >>> >  >>> >  >   private static LoggerRepository defaultRepository;
 >>> >  >>> >  >
 >>> >  >>> >  >   public static synchronized void init(ServletConfig config)
 >>> >  >>> >  >        throws ServletException {
 >>> >  >>> >  >      if( !initialized ) // set the global RepositorySelector
 >>> >  >>> >  >      {
 >>> >  >>> >  >         defaultRepository = LogManager.getLoggerRepository();
 >>> >  >>> >  >         RepositorySelector theSelector = new
 >>> > MyRepositorySelector();
 >>> >  >>> >  >         LogManager.setRepositorySelector(theSelector, guard);
 >>> >  >>> >  >         initialized = true;
 >>> >  >>> >  >      }
 >>> >  >>> >  >
 >>> >  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
 >>> >  >>> > RootCategory(Level.DEBUG));
 >>> >  >>> >  >      loadLog4JConfig(config, hierarchy);
 >>> >  >>> >  >      ClassLoader loader =
 >>> >  >>> > Thread.currentThread().getContextClassLoader();
 >>> >  >>> >  >      repositories.put(loader, hierarchy);
 >>> >  >>> >  >   }
 >>> >  >>> >  >
 >>> >  >>> >  >   public static synchronized void removeFromRepository() {
 >>> >  >>> >  >
 >>> >  >>> >
 >>> > repositories.remove(Thread.currentThread().getContextClassLoader());
 >>> >  >>> >  >   }
 >>> >  >>> >  >
 >>> >  >>> >  >
 >>> >  >>> >  >   private static void loadLog4JConfig(ServletConfig config,
 >>> >  >>> >  >                                       Hierarchy hierarchy)
 >>> >  >>> >  >                                            throws
 >>> > ServletException {
 >>> >  >>> >  >        try {
 >>> >  >>> >  >
 >>> >  >>> >  >               String strLogProperties =
 >>> >  >>> >  >
 >>> >  >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
 >>> >  >>> >  >               System.out.println("strLogProperties: " +
 >>> >  >>> > strLogProperties);
 >>> >  >>> >  >               Properties logProperties = new Properties();
 >>> >  >>> >  >               try {
 >>> >  >>> >  >
 >>> >  >>> >
 >>> >  >>>
 >>> > >logProperties.load(config.getServletContext().getResourceAsStream(strL
 >>> >  >>> >  >ogProperties));
 >>> >  >>> >  >               } catch (Exception e) {
 >>> >  >>> >  >                       System.out.println("ERROR: Loading
 >>> log4j
 >>> >  >>> > properties: " +
 >>> >  >>> >  >e.getMessage());
 >>> >  >>> >  >                       //e.printStackTrace();
 >>> >  >>> >  >               }
 >>> >  >>> >  >               PropertyConfigurator propConf = new
 >>> >  >>> > PropertyConfigurator();
 >>> >  >>> >  >            propConf.doConfigure(logProperties, hierarchy);
 >>> >  >>> >  >                       } catch (Exception e) {
 >>> >  >>> >  >            throw new ServletException(e);
 >>> >  >>> >  >        }
 >>> >  >>> >  >    }
 >>> >  >>> >  >
 >>> >  >>> >  >   private MyRepositorySelector() {
 >>> >  >>> >  >   }
 >>> >  >>> >  >
 >>> >  >>> >  >   public LoggerRepository getLoggerRepository() {
 >>> >  >>> >  >      ClassLoader loader =
 >>> >  >>> > Thread.currentThread().getContextClassLoader();
 >>> >  >>> >  >      LoggerRepository repository =
 >>> >  >>> >  >(LoggerRepository)repositories.get(loader);
 >>> >  >>> >  >
 >>> >  >>> >  >      if (repository == null) {
 >>> >  >>> >  >          return defaultRepository;
 >>> >  >>> >  >      } else {
 >>> >  >>> >  >          return repository;
 >>> >  >>> >  >      }
 >>> >  >>> >  >   }
 >>> >  >>> >  >}
 >>> >  >>> >  >--
 >>> >  >>> >  >View this message in context:
 >>> >  >>> >
 >>> >  >>>
 >>> > >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>> >  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
 >>> >  >>> >  >Sent from the Log4j - Users mailing list archive at
 >>> Nabble.com.
 >>> >  >>> >  >
 >>> >  >>> >  >
 >>> >  >>> >
 >>> > >---------------------------------------------------------------------
 >>> >  >>> >  >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 this message in context:
 >>> >  >>>
 >>> >  >>
 >>> >
 >>> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
 >>> >  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>> >  >>>
 >>> >  >>>
 >>> >  >>>
 >>> ---------------------------------------------------------------------
 >>> >  >>> 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 this message in context:
 >>> >
 >>> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
 >>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>> >  >
 >>> >  >
 >>> >  >---------------------------------------------------------------------
 >>> >  >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 this message in context:
 >>>
 >>
 >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
 >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>>
 >>>
 >>> ---------------------------------------------------------------------
 >>> 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 this message in context:
 >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9969473
 >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >
 >
 >---------------------------------------------------------------------
 >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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by sohan <so...@mms.gov>.
I have tried many ways to get this to work..partly successful but overall
can't this to work. I even purchased the manual and reviewed it.

Tried Log4j 1.3, It was like opening a can of worms..weblogic 8.1.6 internal
logging complained, had to revert back to Log4j 1.2 version.

Earlier I was able to log only class files extending Httpservlet which were
identified in web.xml file with load-on-startup values set to 1 and 2.
Looking closely at weblogic startup script, found a configuration file being
set there for weblogic workshop with -Dlog4j.configuration property, once I
commented this out, I was able to log from other class files of the
application however "filter" class files are not being logged, Based on
System.out.... statements, console shows that these filter classes are being
loaded even before the servlet object initializing log4j RepositorySelector
with load-on-startup set to 1 is loaded  At this point I am not getting
default log4j.log file either. Basically, my filter log is lost. Tried
getLogger("pcs") based on logger configuration in properties file, didn't
get any errors not logging.

I made similar changes to my second application, basically copied the
MyRepositorySelector.java file changed the Log4jinit.java file to set
RepositorySelector and Log4j.properties file or Log4j.xml file are similar
with exception of the "log4j.appender.FILE.File", "log4j.logger.regs"
entries, in bold below. Configuration file names are the same.
In this case both log files are being created, however, the application that
is loaded last during startup, only that application's log is being created.
First application's log is not being written after initialization entries,
unless second application is either removed or changes related to
RepositorySelector are reverted.  

log4j.rootLogger=ERROR, FILE, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c -
%m%n
log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601}] %-5p %c:%L -
%m%n
log4j.logger.regs=DEBUG
log4j.logger.doc=DEBUG
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%d{ISO8601}] %-5p %l - %m%n
log4j.appender.FILE.File=regs.log
log4j.appender.FILE.MaxFileSize=1MB
log4j.appender.FILE.MaxBackupIndex=2

After 3 days, At this point I am not sure if I can get this to work!

thanks,
Sohan



Jacob Kjome wrote:
> 
> 
> Looks mostly correct.  You could change jakarta.apache.org or
> logging.apache.org, but that's inconsequential.  Also, you should apply a
> level
> to the root logger, such as <level value="WARN"/>, or maybe set it to
> DEBUG for
> testing.
> 
> See the Log4j Wiki [1] for links to WizardForge (look at the bottom of the
> page), which will walk you through the steps of generating valid Log4j 1.2
> and
> 1.3 compatible config files.
> 
> Just to be clear, I'm not advocating moving to Log4j 1.3, as it may never
> be
> fully released outside of alpha builds.  I just want to to try it out
> since it
> currently has a working JNDIContextSelector that you can use to test
> against. 
> It's a selector that I know, at least in my testing, works.  If you find
> it to
> work for you, you can adapt it to create your own selector which would be
> compatible with Log4j 1.2.  I also forgot to mention that I created a
> Log4j-1.2
> compatible ContextJNDISelector in the log4j sandbox [2].  It works
> slightly
> differently than the one in Log4j-1.3, but it might provide a good base
> for you
> to start from.
> 
> [1] http://wiki.apache.org/logging-log4j/Log4JProjectPages
> [2]
> http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/
> 
> 
> Jake
> 
> Quoting sohan <so...@mms.gov>:
> 
>>
>> Hi jake,
>>
>> Before I start using Log4j-1.3, I want to confirm if my Log4j.xml is
>> valid
>> for my requirements
>> Below is the xml..I removed SYSTEM entry as I was getting log4j.dtd file
>> not
>> found error during weblogic startup.
>> In this xml do I need to specify logger entry? Am I missing anything!
>>
>> thanks,
>> Sohan
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE log4j:configuration >
>>
>> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>> debug="false">
>>
>>    <!-- A time/date based rolling appender -->
>>    <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log -->
>>    <!-- <appender name="TEST"
>> class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
>>    <appender name="TEST" class="org.apache.log4j.RollingFileAppender">
>>       <!-- <errorHandler
>> class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
>>       <param name="File" value="pcs.log"/>
>>       <param name="Append" value="false"/>
>>
>>       <!-- Rollover at midnight each day -->
>>        <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->
>>
>>       <layout class="org.apache.log4j.PatternLayout">
>>          <!-- The default pattern: Date Priority [Category] Message\n -->
>>          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
>>
>>          <!-- The full pattern: Date MS Priority [Category] (Thread:NDC)
>> Message\n
>>          <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
>> %m%n"/>
>>           -->
>>       </layout>
>>    </appender>
>>
>>    <!-- ======================= -->
>>    <!-- Setup the Root category -->
>>    <!-- ======================= -->
>>
>>    <root>
>>       <appender-ref ref="TEST"/>
>>    </root>
>>
>> </log4j:configuration>
>>
>>
>> Jacob Kjome wrote:
>> >
>> >
>> > Have you tried using the JNDI repository selector solution, such as
>> > in Log4j-1.3?  To test this out quickly, you could just try using
>> > Log4j-1.3 and its ContextJNDISelector class to perform the repository
>> > selection.  I know it works.  I'm not sure why you are seeing odd
>> > results with the classloader-based selector you wrote, but I haven't
>> > gone over the code intensively either.  In any case, don't use a
>> > classloader-based approach.  It will give you nothing but headaches,
>> > in my experience.
>> >
>> > Add the following to your server startup script...
>> >
>> > -Dlog4j.repositorySelector=JNDI
>> >
>> >
>> > Add the following to your web.xml....
>> >
>> >      <listener>
>> >          <!-- this feature may require building Log4j-1.3 from
>> > source, as it may not be in the latest released alpha jar??? -->
>> >
>> >
>>
> <listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL</listener-class>
>> >      </listener>
>> >
>> >      <env-entry>
>> >          <description>JNDI logging context for this app</description>
>> >          <env-entry-name>log4j/context-name</env-entry-name>
>> >          <env-entry-value>myapp</env-entry-value>
>> >          <env-entry-type>java.lang.String</env-entry-type>
>> >      </env-entry>
>> >
>> >      <env-entry>
>> >          <description>URL for configuring log4j context</description>
>> >          <env-entry-name>log4j/configuration-resource</env-entry-name>
>> >          <env-entry-value>myapp-log4j.xml</env-entry-value>
>> >          <env-entry-type>java.lang.String</env-entry-type>
>> >      </env-entry>
>> >
>> >
>> > Jake
>> >
>> > At 07:08 PM 4/10/2007, you wrote:
>> >  >
>> >  >"What do you mean "'pcs' is the log file name"?  That would be the
>> > logger
>> >  >name,
>> >  >not the file name."
>> >  >My mistake, I meant to say that it is both the logger name as well as
>> I
>> >  >named the log file name same too after the application name.
>> >  > I tried with both LogFactory of commons-logging as well as direct
>> use
>> > of
>> >  >Log4j. Behavior is the same
>> >  >I did notice one thing, Log information is being written normally
>> from
>> > java
>> >  >classes that extend HttpServlet.
>> >  >Logging from other java class files is not working as intended. My
>> >  >application uses struts 1.2.9 too.
>> >  >
>> >  >thanks,
>> >  >Sohan
>> >  >
>> >  >
>> >  >Jacob Kjome wrote:
>> >  >>
>> >  >> Quoting sohan <so...@mms.gov>:
>> >  >>
>> >  >>>
>> >  >>> I changed to use Log4j.xml from Log4j.properties and also changed
>> to
>> >  >>> non-static loggers and with in the static methods followed the
>> link
>> >  >>> examples. Now the logging is taking place only for the loggers
>> > mentioned
>> >  >>> in
>> >  >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the
>> > log
>> >  >>> file
>> >  >>> name.
>> >  >>>
>> >  >>
>> >  >> What do you mean "'pcs' is the log file name"?  That would be the
>> > logger
>> >  >> name,
>> >  >> not the file name.
>> >  >>
>> >  >> Also, I didn't mean to direct you to use commons-logging.  If you
>> were
>> >  >> using
>> >  >> log4j directly, please keep using it.  In fact, log wrappers like
>> > SLF4J
>> >  >> and
>> >  >> commons-logging have issues when it comes to repository selectors.
>> > Search
>> >  >> the
>> >  >> SLF4J user list for details on this.  There's also a bug in the
>> SLF4J
>> >  >> database
>> >  >> about this.  I believe the same applies to commons-logging.  Log4j
>> > cannot
>> >  >> guarantee proper logging separation when you use a wrapper.
>> >  >>
>> >  >>> Any idea as to why the non static logger is not working!
>> >  >>>
>> >  >>
>> >  >> I would guess it's because you are using commons-logging.  Use
>> Log4j
>> >  >> directly,
>> >  >> just as you were previously.  I only sent you the commons-logging
>> link
>> >  >> because
>> >  >> they had a good synopsis of the static logger issue, not to
>> convince
>> > you
>> >  >> to
>> >  >> move to commons-logging.
>> >  >>
>> >  >>
>> >  >> Jake
>> >  >>
>> >  >>> thanks,
>> >  >>> Sohan
>> >  >>>
>> >  >>>
>> >  >>> Jacob Kjome wrote:
>> >  >>> >
>> >  >>> >
>> >  >>> > 1.  Use non-static loggers (for Serializable classes, you'll
>> need
>> > to
>> >  >>> > mark these as transient)
>> >  >>> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
>> >  >>> > selectors.  There's already one written for Log4j-1.3alpha. 
>> Even
>> > if
>> >  >>> > you don't care to use 1.3, you can use it to get an idea of how
>> to
>> >  >>> > write one for 1.2.
>> >  >>> >
>> >  >>> >
>> >  >>> > See:
>> >  >>> > http://www.qos.ch/logging/sc.jsp
>> >  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>> >  >>> >
>> >  >>> >
>> >  >>> > Jake
>> >  >>> >
>> >  >>> > At 03:09 PM 4/9/2007, you wrote:
>> >  >>> >  >
>> >  >>> >  >I followed some examples on the web to use RepositorySelector
>> to
>> >  >>> > implement
>> >  >>> >  >separate logging for 2 applications deployed on the same
>> instance
>> > of
>> >  >>> >  >weblogic server. I have the Lgo4j.properties file under
>> Web-Inf/
>> >  >>> folder,
>> >  >>> >  >This is loaded through web.xml file through a startup servlet.
>> >  >>> Problem
>> >  >>> > is
>> >  >>> >  >logging is taking place either in Log4j.log file or other
>> >  >>> applications
>> >  >>> > log
>> >  >>> >  >file. In each java class file, I use..
>> >  >>> >  >       private static Logger log =
>> >  >>> Logger.getLogger(LoginFilter.class);
>> >  >>> >  >and call the log .info ..accordingly. In log4j properties
>> file,
>> > only
>> >  >>> >  >difference is file name for 2 applications.
>> >  >>> >  >
>> >  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
>> >  >>> >  >
>> >  >>> >  >thanks for the help
>> >  >>> >  >Sohan
>> >  >>> >  >
>> >  >>> >  >web.xml entry...
>> >  >>> >  >
>> >  >>> >  >       <servlet>
>> >  >>> >  >               <servlet-name>log4j-init</servlet-name>
>> >  >>> >  >
>> >  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
>> >  >>> >  >           <init-param>
>> >  >>> >  >                   <param-name>Log4JProperties</param-name>
>> >  >>> >  >
>> >  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
>> >  >>> >  >           </init-param>
>> >  >>> >  >           <init-param>
>> >  >>> >  >                   <param-name>LogToFileOnly</param-name>
>> >  >>> >  >                   <param-value>false</param-value>
>> >  >>> >  >           </init-param>
>> >  >>> >  >               <load-on-startup>1</load-on-startup>
>> >  >>> >  >       </servlet>
>> >  >>> >  >
>> >  >>> >  >public class Log4jInit extends HttpServlet {
>> >  >>> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
>> >  >>> >  >       public void init() throws ServletException {
>> >  >>> >  >
>> >  >>> >
>> > System.out.println("\n\n---------------Log4jInit---------------\n\n");
>> >  >>> >
>> >  >>> >  >
>> > MyRepositorySelector.init(this.getServletConfig());
>> >  >>> >  >               Logger log = Logger.getLogger(this.getClass());
>> >  >>> >  >               log.info("Log message from Log4jInit servlet");
>> >  >>> >  >              
>> System.out.println("\n\n---------------Log4jInit:
>> >  >>> >  >Complete---------------\n\n");
>> >  >>> >  >
>> >  >>> >  >       }
>> >  >>> >  >
>> >  >>> >  >}
>> >  >>> >  >
>> >  >>> >  >public class MyRepositorySelector implements
>> RepositorySelector
>> >  >>> >  >{
>> >  >>> >  >   private static boolean initialized = false;
>> >  >>> >  >   private static Object guard = LogManager.getRootLogger();
>> >  >>> >  >
>> >  >>> >  >   private static Map repositories = new HashMap();
>> >  >>> >  >   private static LoggerRepository defaultRepository;
>> >  >>> >  >
>> >  >>> >  >   public static synchronized void init(ServletConfig config)
>> >  >>> >  >        throws ServletException {
>> >  >>> >  >      if( !initialized ) // set the global RepositorySelector
>> >  >>> >  >      {
>> >  >>> >  >         defaultRepository = LogManager.getLoggerRepository();
>> >  >>> >  >         RepositorySelector theSelector = new
>> > MyRepositorySelector();
>> >  >>> >  >         LogManager.setRepositorySelector(theSelector, guard);
>> >  >>> >  >         initialized = true;
>> >  >>> >  >      }
>> >  >>> >  >
>> >  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
>> >  >>> > RootCategory(Level.DEBUG));
>> >  >>> >  >      loadLog4JConfig(config, hierarchy);
>> >  >>> >  >      ClassLoader loader =
>> >  >>> > Thread.currentThread().getContextClassLoader();
>> >  >>> >  >      repositories.put(loader, hierarchy);
>> >  >>> >  >   }
>> >  >>> >  >
>> >  >>> >  >   public static synchronized void removeFromRepository() {
>> >  >>> >  >
>> >  >>> >
>> > repositories.remove(Thread.currentThread().getContextClassLoader());
>> >  >>> >  >   }
>> >  >>> >  >
>> >  >>> >  >
>> >  >>> >  >   private static void loadLog4JConfig(ServletConfig config,
>> >  >>> >  >                                       Hierarchy hierarchy)
>> >  >>> >  >                                            throws
>> > ServletException {
>> >  >>> >  >        try {
>> >  >>> >  >
>> >  >>> >  >               String strLogProperties =
>> >  >>> >  >
>> >  >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
>> >  >>> >  >               System.out.println("strLogProperties: " +
>> >  >>> > strLogProperties);
>> >  >>> >  >               Properties logProperties = new Properties();
>> >  >>> >  >               try {
>> >  >>> >  >
>> >  >>> >
>> >  >>>
>> > >logProperties.load(config.getServletContext().getResourceAsStream(strL
>> >  >>> >  >ogProperties));
>> >  >>> >  >               } catch (Exception e) {
>> >  >>> >  >                       System.out.println("ERROR: Loading
>> log4j
>> >  >>> > properties: " +
>> >  >>> >  >e.getMessage());
>> >  >>> >  >                       //e.printStackTrace();
>> >  >>> >  >               }
>> >  >>> >  >               PropertyConfigurator propConf = new
>> >  >>> > PropertyConfigurator();
>> >  >>> >  >            propConf.doConfigure(logProperties, hierarchy);
>> >  >>> >  >                       } catch (Exception e) {
>> >  >>> >  >            throw new ServletException(e);
>> >  >>> >  >        }
>> >  >>> >  >    }
>> >  >>> >  >
>> >  >>> >  >   private MyRepositorySelector() {
>> >  >>> >  >   }
>> >  >>> >  >
>> >  >>> >  >   public LoggerRepository getLoggerRepository() {
>> >  >>> >  >      ClassLoader loader =
>> >  >>> > Thread.currentThread().getContextClassLoader();
>> >  >>> >  >      LoggerRepository repository =
>> >  >>> >  >(LoggerRepository)repositories.get(loader);
>> >  >>> >  >
>> >  >>> >  >      if (repository == null) {
>> >  >>> >  >          return defaultRepository;
>> >  >>> >  >      } else {
>> >  >>> >  >          return repository;
>> >  >>> >  >      }
>> >  >>> >  >   }
>> >  >>> >  >}
>> >  >>> >  >--
>> >  >>> >  >View this message in context:
>> >  >>> >
>> >  >>>
>> > >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>> >  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
>> >  >>> >  >Sent from the Log4j - Users mailing list archive at
>> Nabble.com.
>> >  >>> >  >
>> >  >>> >  >
>> >  >>> >
>> > >---------------------------------------------------------------------
>> >  >>> >  >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 this message in context:
>> >  >>>
>> >  >>
>> > 
>> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
>> >  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>> >  >>>
>> >  >>>
>> >  >>>
>> ---------------------------------------------------------------------
>> >  >>> 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 this message in context:
>> > 
>> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>> >  >
>> >  >
>> >  >---------------------------------------------------------------------
>> >  >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 this message in context:
>>
> http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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 this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9969473
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by Jacob Kjome <ho...@visi.com>.
Looks mostly correct.  You could change jakarta.apache.org or
logging.apache.org, but that's inconsequential.  Also, you should apply a level
to the root logger, such as <level value="WARN"/>, or maybe set it to DEBUG for
testing.

See the Log4j Wiki [1] for links to WizardForge (look at the bottom of the
page), which will walk you through the steps of generating valid Log4j 1.2 and
1.3 compatible config files.

Just to be clear, I'm not advocating moving to Log4j 1.3, as it may never be
fully released outside of alpha builds.  I just want to to try it out since it
currently has a working JNDIContextSelector that you can use to test against. 
It's a selector that I know, at least in my testing, works.  If you find it to
work for you, you can adapt it to create your own selector which would be
compatible with Log4j 1.2.  I also forgot to mention that I created a Log4j-1.2
compatible ContextJNDISelector in the log4j sandbox [2].  It works slightly
differently than the one in Log4j-1.3, but it might provide a good base for you
to start from.

[1] http://wiki.apache.org/logging-log4j/Log4JProjectPages
[2]
http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/selector/


Jake

Quoting sohan <so...@mms.gov>:

>
> Hi jake,
>
> Before I start using Log4j-1.3, I want to confirm if my Log4j.xml is valid
> for my requirements
> Below is the xml..I removed SYSTEM entry as I was getting log4j.dtd file not
> found error during weblogic startup.
> In this xml do I need to specify logger entry? Am I missing anything!
>
> thanks,
> Sohan
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE log4j:configuration >
>
> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
> debug="false">
>
>    <!-- A time/date based rolling appender -->
>    <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log -->
>    <!-- <appender name="TEST"
> class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
>    <appender name="TEST" class="org.apache.log4j.RollingFileAppender">
>       <!-- <errorHandler
> class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
>       <param name="File" value="pcs.log"/>
>       <param name="Append" value="false"/>
>
>       <!-- Rollover at midnight each day -->
>        <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->
>
>       <layout class="org.apache.log4j.PatternLayout">
>          <!-- The default pattern: Date Priority [Category] Message\n -->
>          <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
>
>          <!-- The full pattern: Date MS Priority [Category] (Thread:NDC)
> Message\n
>          <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
> %m%n"/>
>           -->
>       </layout>
>    </appender>
>
>    <!-- ======================= -->
>    <!-- Setup the Root category -->
>    <!-- ======================= -->
>
>    <root>
>       <appender-ref ref="TEST"/>
>    </root>
>
> </log4j:configuration>
>
>
> Jacob Kjome wrote:
> >
> >
> > Have you tried using the JNDI repository selector solution, such as
> > in Log4j-1.3?  To test this out quickly, you could just try using
> > Log4j-1.3 and its ContextJNDISelector class to perform the repository
> > selection.  I know it works.  I'm not sure why you are seeing odd
> > results with the classloader-based selector you wrote, but I haven't
> > gone over the code intensively either.  In any case, don't use a
> > classloader-based approach.  It will give you nothing but headaches,
> > in my experience.
> >
> > Add the following to your server startup script...
> >
> > -Dlog4j.repositorySelector=JNDI
> >
> >
> > Add the following to your web.xml....
> >
> >      <listener>
> >          <!-- this feature may require building Log4j-1.3 from
> > source, as it may not be in the latest released alpha jar??? -->
> >
> >
>
<listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL</listener-class>
> >      </listener>
> >
> >      <env-entry>
> >          <description>JNDI logging context for this app</description>
> >          <env-entry-name>log4j/context-name</env-entry-name>
> >          <env-entry-value>myapp</env-entry-value>
> >          <env-entry-type>java.lang.String</env-entry-type>
> >      </env-entry>
> >
> >      <env-entry>
> >          <description>URL for configuring log4j context</description>
> >          <env-entry-name>log4j/configuration-resource</env-entry-name>
> >          <env-entry-value>myapp-log4j.xml</env-entry-value>
> >          <env-entry-type>java.lang.String</env-entry-type>
> >      </env-entry>
> >
> >
> > Jake
> >
> > At 07:08 PM 4/10/2007, you wrote:
> >  >
> >  >"What do you mean "'pcs' is the log file name"?  That would be the
> > logger
> >  >name,
> >  >not the file name."
> >  >My mistake, I meant to say that it is both the logger name as well as I
> >  >named the log file name same too after the application name.
> >  > I tried with both LogFactory of commons-logging as well as direct use
> > of
> >  >Log4j. Behavior is the same
> >  >I did notice one thing, Log information is being written normally from
> > java
> >  >classes that extend HttpServlet.
> >  >Logging from other java class files is not working as intended. My
> >  >application uses struts 1.2.9 too.
> >  >
> >  >thanks,
> >  >Sohan
> >  >
> >  >
> >  >Jacob Kjome wrote:
> >  >>
> >  >> Quoting sohan <so...@mms.gov>:
> >  >>
> >  >>>
> >  >>> I changed to use Log4j.xml from Log4j.properties and also changed to
> >  >>> non-static loggers and with in the static methods followed the link
> >  >>> examples. Now the logging is taking place only for the loggers
> > mentioned
> >  >>> in
> >  >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the
> > log
> >  >>> file
> >  >>> name.
> >  >>>
> >  >>
> >  >> What do you mean "'pcs' is the log file name"?  That would be the
> > logger
> >  >> name,
> >  >> not the file name.
> >  >>
> >  >> Also, I didn't mean to direct you to use commons-logging.  If you were
> >  >> using
> >  >> log4j directly, please keep using it.  In fact, log wrappers like
> > SLF4J
> >  >> and
> >  >> commons-logging have issues when it comes to repository selectors.
> > Search
> >  >> the
> >  >> SLF4J user list for details on this.  There's also a bug in the SLF4J
> >  >> database
> >  >> about this.  I believe the same applies to commons-logging.  Log4j
> > cannot
> >  >> guarantee proper logging separation when you use a wrapper.
> >  >>
> >  >>> Any idea as to why the non static logger is not working!
> >  >>>
> >  >>
> >  >> I would guess it's because you are using commons-logging.  Use Log4j
> >  >> directly,
> >  >> just as you were previously.  I only sent you the commons-logging link
> >  >> because
> >  >> they had a good synopsis of the static logger issue, not to convince
> > you
> >  >> to
> >  >> move to commons-logging.
> >  >>
> >  >>
> >  >> Jake
> >  >>
> >  >>> thanks,
> >  >>> Sohan
> >  >>>
> >  >>>
> >  >>> Jacob Kjome wrote:
> >  >>> >
> >  >>> >
> >  >>> > 1.  Use non-static loggers (for Serializable classes, you'll need
> > to
> >  >>> > mark these as transient)
> >  >>> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
> >  >>> > selectors.  There's already one written for Log4j-1.3alpha.  Even
> > if
> >  >>> > you don't care to use 1.3, you can use it to get an idea of how to
> >  >>> > write one for 1.2.
> >  >>> >
> >  >>> >
> >  >>> > See:
> >  >>> > http://www.qos.ch/logging/sc.jsp
> >  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
> >  >>> >
> >  >>> >
> >  >>> > Jake
> >  >>> >
> >  >>> > At 03:09 PM 4/9/2007, you wrote:
> >  >>> >  >
> >  >>> >  >I followed some examples on the web to use RepositorySelector to
> >  >>> > implement
> >  >>> >  >separate logging for 2 applications deployed on the same instance
> > of
> >  >>> >  >weblogic server. I have the Lgo4j.properties file under Web-Inf/
> >  >>> folder,
> >  >>> >  >This is loaded through web.xml file through a startup servlet.
> >  >>> Problem
> >  >>> > is
> >  >>> >  >logging is taking place either in Log4j.log file or other
> >  >>> applications
> >  >>> > log
> >  >>> >  >file. In each java class file, I use..
> >  >>> >  >       private static Logger log =
> >  >>> Logger.getLogger(LoginFilter.class);
> >  >>> >  >and call the log .info ..accordingly. In log4j properties file,
> > only
> >  >>> >  >difference is file name for 2 applications.
> >  >>> >  >
> >  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
> >  >>> >  >
> >  >>> >  >thanks for the help
> >  >>> >  >Sohan
> >  >>> >  >
> >  >>> >  >web.xml entry...
> >  >>> >  >
> >  >>> >  >       <servlet>
> >  >>> >  >               <servlet-name>log4j-init</servlet-name>
> >  >>> >  >
> >  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
> >  >>> >  >           <init-param>
> >  >>> >  >                   <param-name>Log4JProperties</param-name>
> >  >>> >  >
> >  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
> >  >>> >  >           </init-param>
> >  >>> >  >           <init-param>
> >  >>> >  >                   <param-name>LogToFileOnly</param-name>
> >  >>> >  >                   <param-value>false</param-value>
> >  >>> >  >           </init-param>
> >  >>> >  >               <load-on-startup>1</load-on-startup>
> >  >>> >  >       </servlet>
> >  >>> >  >
> >  >>> >  >public class Log4jInit extends HttpServlet {
> >  >>> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
> >  >>> >  >       public void init() throws ServletException {
> >  >>> >  >
> >  >>> >
> > System.out.println("\n\n---------------Log4jInit---------------\n\n");
> >  >>> >
> >  >>> >  >
> > MyRepositorySelector.init(this.getServletConfig());
> >  >>> >  >               Logger log = Logger.getLogger(this.getClass());
> >  >>> >  >               log.info("Log message from Log4jInit servlet");
> >  >>> >  >               System.out.println("\n\n---------------Log4jInit:
> >  >>> >  >Complete---------------\n\n");
> >  >>> >  >
> >  >>> >  >       }
> >  >>> >  >
> >  >>> >  >}
> >  >>> >  >
> >  >>> >  >public class MyRepositorySelector implements RepositorySelector
> >  >>> >  >{
> >  >>> >  >   private static boolean initialized = false;
> >  >>> >  >   private static Object guard = LogManager.getRootLogger();
> >  >>> >  >
> >  >>> >  >   private static Map repositories = new HashMap();
> >  >>> >  >   private static LoggerRepository defaultRepository;
> >  >>> >  >
> >  >>> >  >   public static synchronized void init(ServletConfig config)
> >  >>> >  >        throws ServletException {
> >  >>> >  >      if( !initialized ) // set the global RepositorySelector
> >  >>> >  >      {
> >  >>> >  >         defaultRepository = LogManager.getLoggerRepository();
> >  >>> >  >         RepositorySelector theSelector = new
> > MyRepositorySelector();
> >  >>> >  >         LogManager.setRepositorySelector(theSelector, guard);
> >  >>> >  >         initialized = true;
> >  >>> >  >      }
> >  >>> >  >
> >  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
> >  >>> > RootCategory(Level.DEBUG));
> >  >>> >  >      loadLog4JConfig(config, hierarchy);
> >  >>> >  >      ClassLoader loader =
> >  >>> > Thread.currentThread().getContextClassLoader();
> >  >>> >  >      repositories.put(loader, hierarchy);
> >  >>> >  >   }
> >  >>> >  >
> >  >>> >  >   public static synchronized void removeFromRepository() {
> >  >>> >  >
> >  >>> >
> > repositories.remove(Thread.currentThread().getContextClassLoader());
> >  >>> >  >   }
> >  >>> >  >
> >  >>> >  >
> >  >>> >  >   private static void loadLog4JConfig(ServletConfig config,
> >  >>> >  >                                       Hierarchy hierarchy)
> >  >>> >  >                                            throws
> > ServletException {
> >  >>> >  >        try {
> >  >>> >  >
> >  >>> >  >               String strLogProperties =
> >  >>> >  >
> >  >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
> >  >>> >  >               System.out.println("strLogProperties: " +
> >  >>> > strLogProperties);
> >  >>> >  >               Properties logProperties = new Properties();
> >  >>> >  >               try {
> >  >>> >  >
> >  >>> >
> >  >>>
> > >logProperties.load(config.getServletContext().getResourceAsStream(strL
> >  >>> >  >ogProperties));
> >  >>> >  >               } catch (Exception e) {
> >  >>> >  >                       System.out.println("ERROR: Loading log4j
> >  >>> > properties: " +
> >  >>> >  >e.getMessage());
> >  >>> >  >                       //e.printStackTrace();
> >  >>> >  >               }
> >  >>> >  >               PropertyConfigurator propConf = new
> >  >>> > PropertyConfigurator();
> >  >>> >  >            propConf.doConfigure(logProperties, hierarchy);
> >  >>> >  >                       } catch (Exception e) {
> >  >>> >  >            throw new ServletException(e);
> >  >>> >  >        }
> >  >>> >  >    }
> >  >>> >  >
> >  >>> >  >   private MyRepositorySelector() {
> >  >>> >  >   }
> >  >>> >  >
> >  >>> >  >   public LoggerRepository getLoggerRepository() {
> >  >>> >  >      ClassLoader loader =
> >  >>> > Thread.currentThread().getContextClassLoader();
> >  >>> >  >      LoggerRepository repository =
> >  >>> >  >(LoggerRepository)repositories.get(loader);
> >  >>> >  >
> >  >>> >  >      if (repository == null) {
> >  >>> >  >          return defaultRepository;
> >  >>> >  >      } else {
> >  >>> >  >          return repository;
> >  >>> >  >      }
> >  >>> >  >   }
> >  >>> >  >}
> >  >>> >  >--
> >  >>> >  >View this message in context:
> >  >>> >
> >  >>>
> > >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
> >  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
> >  >>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
> >  >>> >  >
> >  >>> >  >
> >  >>> >
> > >---------------------------------------------------------------------
> >  >>> >  >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 this message in context:
> >  >>>
> >  >>
> >  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
> >  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
> >  >>>
> >  >>>
> >  >>> ---------------------------------------------------------------------
> >  >>> 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 this message in context:
> >  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
> >  >
> >  >
> >  >---------------------------------------------------------------------
> >  >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 this message in context:
>
http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by sohan <so...@mms.gov>.
Hi jake,

Before I start using Log4j-1.3, I want to confirm if my Log4j.xml is valid
for my requirements
Below is the xml..I removed SYSTEM entry as I was getting log4j.dtd file not
found error during weblogic startup.
In this xml do I need to specify logger entry? Am I missing anything!

thanks,
Sohan

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration >

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">

   <!-- A time/date based rolling appender -->
   <!-- Logs messages to ${jboss.server.home.dir}/log/test1.log -->
   <!-- <appender name="TEST"
class="org.jboss.logging.appender.DailyRollingFileAppender"> -->
   <appender name="TEST" class="org.apache.log4j.RollingFileAppender">
      <!-- <errorHandler
class="org.jboss.logging.util.OnlyOnceErrorHandler"/> -->
      <param name="File" value="pcs.log"/>
      <param name="Append" value="false"/>

      <!-- Rollover at midnight each day -->
       <!-- <param name="DatePattern" value="'.'yyyy-MM-dd"/> -->

      <layout class="org.apache.log4j.PatternLayout">
         <!-- The default pattern: Date Priority [Category] Message\n -->
         <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>

         <!-- The full pattern: Date MS Priority [Category] (Thread:NDC)
Message\n
         <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
          -->
      </layout>
   </appender>

   <!-- ======================= -->
   <!-- Setup the Root category -->
   <!-- ======================= -->

   <root>
      <appender-ref ref="TEST"/>
   </root>

</log4j:configuration>


Jacob Kjome wrote:
> 
> 
> Have you tried using the JNDI repository selector solution, such as 
> in Log4j-1.3?  To test this out quickly, you could just try using 
> Log4j-1.3 and its ContextJNDISelector class to perform the repository 
> selection.  I know it works.  I'm not sure why you are seeing odd 
> results with the classloader-based selector you wrote, but I haven't 
> gone over the code intensively either.  In any case, don't use a 
> classloader-based approach.  It will give you nothing but headaches, 
> in my experience.
> 
> Add the following to your server startup script...
> 
> -Dlog4j.repositorySelector=JNDI
> 
> 
> Add the following to your web.xml....
> 
>      <listener>
>          <!-- this feature may require building Log4j-1.3 from 
> source, as it may not be in the latest released alpha jar??? -->
>         
> <listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL</listener-class>
>      </listener>
> 
>      <env-entry>
>          <description>JNDI logging context for this app</description>
>          <env-entry-name>log4j/context-name</env-entry-name>
>          <env-entry-value>myapp</env-entry-value>
>          <env-entry-type>java.lang.String</env-entry-type>
>      </env-entry>
> 
>      <env-entry>
>          <description>URL for configuring log4j context</description>
>          <env-entry-name>log4j/configuration-resource</env-entry-name>
>          <env-entry-value>myapp-log4j.xml</env-entry-value>
>          <env-entry-type>java.lang.String</env-entry-type>
>      </env-entry>
> 
> 
> Jake
> 
> At 07:08 PM 4/10/2007, you wrote:
>  >
>  >"What do you mean "'pcs' is the log file name"?  That would be the
> logger
>  >name,
>  >not the file name."
>  >My mistake, I meant to say that it is both the logger name as well as I
>  >named the log file name same too after the application name.
>  > I tried with both LogFactory of commons-logging as well as direct use
> of
>  >Log4j. Behavior is the same
>  >I did notice one thing, Log information is being written normally from
> java
>  >classes that extend HttpServlet.
>  >Logging from other java class files is not working as intended. My
>  >application uses struts 1.2.9 too.
>  >
>  >thanks,
>  >Sohan
>  >
>  >
>  >Jacob Kjome wrote:
>  >>
>  >> Quoting sohan <so...@mms.gov>:
>  >>
>  >>>
>  >>> I changed to use Log4j.xml from Log4j.properties and also changed to
>  >>> non-static loggers and with in the static methods followed the link
>  >>> examples. Now the logging is taking place only for the loggers
> mentioned
>  >>> in
>  >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the
> log
>  >>> file
>  >>> name.
>  >>>
>  >>
>  >> What do you mean "'pcs' is the log file name"?  That would be the
> logger
>  >> name,
>  >> not the file name.
>  >>
>  >> Also, I didn't mean to direct you to use commons-logging.  If you were
>  >> using
>  >> log4j directly, please keep using it.  In fact, log wrappers like
> SLF4J
>  >> and
>  >> commons-logging have issues when it comes to repository selectors. 
> Search
>  >> the
>  >> SLF4J user list for details on this.  There's also a bug in the SLF4J
>  >> database
>  >> about this.  I believe the same applies to commons-logging.  Log4j
> cannot
>  >> guarantee proper logging separation when you use a wrapper.
>  >>
>  >>> Any idea as to why the non static logger is not working!
>  >>>
>  >>
>  >> I would guess it's because you are using commons-logging.  Use Log4j
>  >> directly,
>  >> just as you were previously.  I only sent you the commons-logging link
>  >> because
>  >> they had a good synopsis of the static logger issue, not to convince
> you
>  >> to
>  >> move to commons-logging.
>  >>
>  >>
>  >> Jake
>  >>
>  >>> thanks,
>  >>> Sohan
>  >>>
>  >>>
>  >>> Jacob Kjome wrote:
>  >>> >
>  >>> >
>  >>> > 1.  Use non-static loggers (for Serializable classes, you'll need
> to
>  >>> > mark these as transient)
>  >>> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
>  >>> > selectors.  There's already one written for Log4j-1.3alpha.  Even
> if
>  >>> > you don't care to use 1.3, you can use it to get an idea of how to
>  >>> > write one for 1.2.
>  >>> >
>  >>> >
>  >>> > See:
>  >>> > http://www.qos.ch/logging/sc.jsp
>  >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>  >>> >
>  >>> >
>  >>> > Jake
>  >>> >
>  >>> > At 03:09 PM 4/9/2007, you wrote:
>  >>> >  >
>  >>> >  >I followed some examples on the web to use RepositorySelector to
>  >>> > implement
>  >>> >  >separate logging for 2 applications deployed on the same instance
> of
>  >>> >  >weblogic server. I have the Lgo4j.properties file under Web-Inf/
>  >>> folder,
>  >>> >  >This is loaded through web.xml file through a startup servlet.
>  >>> Problem
>  >>> > is
>  >>> >  >logging is taking place either in Log4j.log file or other
>  >>> applications
>  >>> > log
>  >>> >  >file. In each java class file, I use..
>  >>> >  >       private static Logger log =
>  >>> Logger.getLogger(LoginFilter.class);
>  >>> >  >and call the log .info ..accordingly. In log4j properties file,
> only
>  >>> >  >difference is file name for 2 applications.
>  >>> >  >
>  >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
>  >>> >  >
>  >>> >  >thanks for the help
>  >>> >  >Sohan
>  >>> >  >
>  >>> >  >web.xml entry...
>  >>> >  >
>  >>> >  >       <servlet>
>  >>> >  >               <servlet-name>log4j-init</servlet-name>
>  >>> >  >
>  >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
>  >>> >  >           <init-param>
>  >>> >  >                   <param-name>Log4JProperties</param-name>
>  >>> >  >
>  >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
>  >>> >  >           </init-param>
>  >>> >  >           <init-param>
>  >>> >  >                   <param-name>LogToFileOnly</param-name>
>  >>> >  >                   <param-value>false</param-value>
>  >>> >  >           </init-param>
>  >>> >  >               <load-on-startup>1</load-on-startup>
>  >>> >  >       </servlet>
>  >>> >  >
>  >>> >  >public class Log4jInit extends HttpServlet {
>  >>> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
>  >>> >  >       public void init() throws ServletException {
>  >>> >  >
>  >>> >
> System.out.println("\n\n---------------Log4jInit---------------\n\n");
>  >>> >
>  >>> >  >              
> MyRepositorySelector.init(this.getServletConfig());
>  >>> >  >               Logger log = Logger.getLogger(this.getClass());
>  >>> >  >               log.info("Log message from Log4jInit servlet");
>  >>> >  >               System.out.println("\n\n---------------Log4jInit:
>  >>> >  >Complete---------------\n\n");
>  >>> >  >
>  >>> >  >       }
>  >>> >  >
>  >>> >  >}
>  >>> >  >
>  >>> >  >public class MyRepositorySelector implements RepositorySelector
>  >>> >  >{
>  >>> >  >   private static boolean initialized = false;
>  >>> >  >   private static Object guard = LogManager.getRootLogger();
>  >>> >  >
>  >>> >  >   private static Map repositories = new HashMap();
>  >>> >  >   private static LoggerRepository defaultRepository;
>  >>> >  >
>  >>> >  >   public static synchronized void init(ServletConfig config)
>  >>> >  >        throws ServletException {
>  >>> >  >      if( !initialized ) // set the global RepositorySelector
>  >>> >  >      {
>  >>> >  >         defaultRepository = LogManager.getLoggerRepository();
>  >>> >  >         RepositorySelector theSelector = new
> MyRepositorySelector();
>  >>> >  >         LogManager.setRepositorySelector(theSelector, guard);
>  >>> >  >         initialized = true;
>  >>> >  >      }
>  >>> >  >
>  >>> >  >      Hierarchy hierarchy = new Hierarchy(new
>  >>> > RootCategory(Level.DEBUG));
>  >>> >  >      loadLog4JConfig(config, hierarchy);
>  >>> >  >      ClassLoader loader =
>  >>> > Thread.currentThread().getContextClassLoader();
>  >>> >  >      repositories.put(loader, hierarchy);
>  >>> >  >   }
>  >>> >  >
>  >>> >  >   public static synchronized void removeFromRepository() {
>  >>> >  >
>  >>> >
> repositories.remove(Thread.currentThread().getContextClassLoader());
>  >>> >  >   }
>  >>> >  >
>  >>> >  >
>  >>> >  >   private static void loadLog4JConfig(ServletConfig config,
>  >>> >  >                                       Hierarchy hierarchy)
>  >>> >  >                                            throws
> ServletException {
>  >>> >  >        try {
>  >>> >  >
>  >>> >  >               String strLogProperties =
>  >>> >  >
>  >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
>  >>> >  >               System.out.println("strLogProperties: " +
>  >>> > strLogProperties);
>  >>> >  >               Properties logProperties = new Properties();
>  >>> >  >               try {
>  >>> >  >
>  >>> >
>  >>>
> >logProperties.load(config.getServletContext().getResourceAsStream(strL
>  >>> >  >ogProperties));
>  >>> >  >               } catch (Exception e) {
>  >>> >  >                       System.out.println("ERROR: Loading log4j
>  >>> > properties: " +
>  >>> >  >e.getMessage());
>  >>> >  >                       //e.printStackTrace();
>  >>> >  >               }
>  >>> >  >               PropertyConfigurator propConf = new
>  >>> > PropertyConfigurator();
>  >>> >  >            propConf.doConfigure(logProperties, hierarchy);
>  >>> >  >                       } catch (Exception e) {
>  >>> >  >            throw new ServletException(e);
>  >>> >  >        }
>  >>> >  >    }
>  >>> >  >
>  >>> >  >   private MyRepositorySelector() {
>  >>> >  >   }
>  >>> >  >
>  >>> >  >   public LoggerRepository getLoggerRepository() {
>  >>> >  >      ClassLoader loader =
>  >>> > Thread.currentThread().getContextClassLoader();
>  >>> >  >      LoggerRepository repository =
>  >>> >  >(LoggerRepository)repositories.get(loader);
>  >>> >  >
>  >>> >  >      if (repository == null) {
>  >>> >  >          return defaultRepository;
>  >>> >  >      } else {
>  >>> >  >          return repository;
>  >>> >  >      }
>  >>> >  >   }
>  >>> >  >}
>  >>> >  >--
>  >>> >  >View this message in context:
>  >>> >
>  >>>
> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
>  >>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >>> >  >
>  >>> >  >
>  >>> > 
> >---------------------------------------------------------------------
>  >>> >  >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 this message in context:
>  >>>
>  >>
>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
>  >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >>>
>  >>>
>  >>> ---------------------------------------------------------------------
>  >>> 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 this message in context:
>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
>  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >
>  >
>  >---------------------------------------------------------------------
>  >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 this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9941069
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by Jacob Kjome <ho...@visi.com>.
Have you tried using the JNDI repository selector solution, such as 
in Log4j-1.3?  To test this out quickly, you could just try using 
Log4j-1.3 and its ContextJNDISelector class to perform the repository 
selection.  I know it works.  I'm not sure why you are seeing odd 
results with the classloader-based selector you wrote, but I haven't 
gone over the code intensively either.  In any case, don't use a 
classloader-based approach.  It will give you nothing but headaches, 
in my experience.

Add the following to your server startup script...

-Dlog4j.repositorySelector=JNDI


Add the following to your web.xml....

     <listener>
         <!-- this feature may require building Log4j-1.3 from 
source, as it may not be in the latest released alpha jar??? -->
         <listener-class>org.apache.log4j.selector.servlet.ContextDetachingSCL</listener-class>
     </listener>

     <env-entry>
         <description>JNDI logging context for this app</description>
         <env-entry-name>log4j/context-name</env-entry-name>
         <env-entry-value>myapp</env-entry-value>
         <env-entry-type>java.lang.String</env-entry-type>
     </env-entry>

     <env-entry>
         <description>URL for configuring log4j context</description>
         <env-entry-name>log4j/configuration-resource</env-entry-name>
         <env-entry-value>myapp-log4j.xml</env-entry-value>
         <env-entry-type>java.lang.String</env-entry-type>
     </env-entry>


Jake

At 07:08 PM 4/10/2007, you wrote:
 >
 >"What do you mean "'pcs' is the log file name"?  That would be the logger
 >name,
 >not the file name."
 >My mistake, I meant to say that it is both the logger name as well as I
 >named the log file name same too after the application name.
 > I tried with both LogFactory of commons-logging as well as direct use of
 >Log4j. Behavior is the same
 >I did notice one thing, Log information is being written normally from java
 >classes that extend HttpServlet.
 >Logging from other java class files is not working as intended. My
 >application uses struts 1.2.9 too.
 >
 >thanks,
 >Sohan
 >
 >
 >Jacob Kjome wrote:
 >>
 >> Quoting sohan <so...@mms.gov>:
 >>
 >>>
 >>> I changed to use Log4j.xml from Log4j.properties and also changed to
 >>> non-static loggers and with in the static methods followed the link
 >>> examples. Now the logging is taking place only for the loggers mentioned
 >>> in
 >>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the log
 >>> file
 >>> name.
 >>>
 >>
 >> What do you mean "'pcs' is the log file name"?  That would be the logger
 >> name,
 >> not the file name.
 >>
 >> Also, I didn't mean to direct you to use commons-logging.  If you were
 >> using
 >> log4j directly, please keep using it.  In fact, log wrappers like SLF4J
 >> and
 >> commons-logging have issues when it comes to repository selectors.  Search
 >> the
 >> SLF4J user list for details on this.  There's also a bug in the SLF4J
 >> database
 >> about this.  I believe the same applies to commons-logging.  Log4j cannot
 >> guarantee proper logging separation when you use a wrapper.
 >>
 >>> Any idea as to why the non static logger is not working!
 >>>
 >>
 >> I would guess it's because you are using commons-logging.  Use Log4j
 >> directly,
 >> just as you were previously.  I only sent you the commons-logging link
 >> because
 >> they had a good synopsis of the static logger issue, not to convince you
 >> to
 >> move to commons-logging.
 >>
 >>
 >> Jake
 >>
 >>> thanks,
 >>> Sohan
 >>>
 >>>
 >>> Jacob Kjome wrote:
 >>> >
 >>> >
 >>> > 1.  Use non-static loggers (for Serializable classes, you'll need to
 >>> > mark these as transient)
 >>> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
 >>> > selectors.  There's already one written for Log4j-1.3alpha.  Even if
 >>> > you don't care to use 1.3, you can use it to get an idea of how to
 >>> > write one for 1.2.
 >>> >
 >>> >
 >>> > See:
 >>> > http://www.qos.ch/logging/sc.jsp
 >>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
 >>> >
 >>> >
 >>> > Jake
 >>> >
 >>> > At 03:09 PM 4/9/2007, you wrote:
 >>> >  >
 >>> >  >I followed some examples on the web to use RepositorySelector to
 >>> > implement
 >>> >  >separate logging for 2 applications deployed on the same instance of
 >>> >  >weblogic server. I have the Lgo4j.properties file under Web-Inf/
 >>> folder,
 >>> >  >This is loaded through web.xml file through a startup servlet.
 >>> Problem
 >>> > is
 >>> >  >logging is taking place either in Log4j.log file or other
 >>> applications
 >>> > log
 >>> >  >file. In each java class file, I use..
 >>> >  >       private static Logger log =
 >>> Logger.getLogger(LoginFilter.class);
 >>> >  >and call the log .info ..accordingly. In log4j properties file, only
 >>> >  >difference is file name for 2 applications.
 >>> >  >
 >>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
 >>> >  >
 >>> >  >thanks for the help
 >>> >  >Sohan
 >>> >  >
 >>> >  >web.xml entry...
 >>> >  >
 >>> >  >       <servlet>
 >>> >  >               <servlet-name>log4j-init</servlet-name>
 >>> >  >
 >>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
 >>> >  >           <init-param>
 >>> >  >                   <param-name>Log4JProperties</param-name>
 >>> >  >
 >>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
 >>> >  >           </init-param>
 >>> >  >           <init-param>
 >>> >  >                   <param-name>LogToFileOnly</param-name>
 >>> >  >                   <param-value>false</param-value>
 >>> >  >           </init-param>
 >>> >  >               <load-on-startup>1</load-on-startup>
 >>> >  >       </servlet>
 >>> >  >
 >>> >  >public class Log4jInit extends HttpServlet {
 >>> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
 >>> >  >       public void init() throws ServletException {
 >>> >  >
 >>> > System.out.println("\n\n---------------Log4jInit---------------\n\n");
 >>> >
 >>> >  >               MyRepositorySelector.init(this.getServletConfig());
 >>> >  >               Logger log = Logger.getLogger(this.getClass());
 >>> >  >               log.info("Log message from Log4jInit servlet");
 >>> >  >               System.out.println("\n\n---------------Log4jInit:
 >>> >  >Complete---------------\n\n");
 >>> >  >
 >>> >  >       }
 >>> >  >
 >>> >  >}
 >>> >  >
 >>> >  >public class MyRepositorySelector implements RepositorySelector
 >>> >  >{
 >>> >  >   private static boolean initialized = false;
 >>> >  >   private static Object guard = LogManager.getRootLogger();
 >>> >  >
 >>> >  >   private static Map repositories = new HashMap();
 >>> >  >   private static LoggerRepository defaultRepository;
 >>> >  >
 >>> >  >   public static synchronized void init(ServletConfig config)
 >>> >  >        throws ServletException {
 >>> >  >      if( !initialized ) // set the global RepositorySelector
 >>> >  >      {
 >>> >  >         defaultRepository = LogManager.getLoggerRepository();
 >>> >  >         RepositorySelector theSelector = new MyRepositorySelector();
 >>> >  >         LogManager.setRepositorySelector(theSelector, guard);
 >>> >  >         initialized = true;
 >>> >  >      }
 >>> >  >
 >>> >  >      Hierarchy hierarchy = new Hierarchy(new
 >>> > RootCategory(Level.DEBUG));
 >>> >  >      loadLog4JConfig(config, hierarchy);
 >>> >  >      ClassLoader loader =
 >>> > Thread.currentThread().getContextClassLoader();
 >>> >  >      repositories.put(loader, hierarchy);
 >>> >  >   }
 >>> >  >
 >>> >  >   public static synchronized void removeFromRepository() {
 >>> >  >
 >>> > repositories.remove(Thread.currentThread().getContextClassLoader());
 >>> >  >   }
 >>> >  >
 >>> >  >
 >>> >  >   private static void loadLog4JConfig(ServletConfig config,
 >>> >  >                                       Hierarchy hierarchy)
 >>> >  >                                            throws ServletException {
 >>> >  >        try {
 >>> >  >
 >>> >  >               String strLogProperties =
 >>> >  >
 >>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
 >>> >  >               System.out.println("strLogProperties: " +
 >>> > strLogProperties);
 >>> >  >               Properties logProperties = new Properties();
 >>> >  >               try {
 >>> >  >
 >>> >
 >>> >logProperties.load(config.getServletContext().getResourceAsStream(strL
 >>> >  >ogProperties));
 >>> >  >               } catch (Exception e) {
 >>> >  >                       System.out.println("ERROR: Loading log4j
 >>> > properties: " +
 >>> >  >e.getMessage());
 >>> >  >                       //e.printStackTrace();
 >>> >  >               }
 >>> >  >               PropertyConfigurator propConf = new
 >>> > PropertyConfigurator();
 >>> >  >            propConf.doConfigure(logProperties, hierarchy);
 >>> >  >                       } catch (Exception e) {
 >>> >  >            throw new ServletException(e);
 >>> >  >        }
 >>> >  >    }
 >>> >  >
 >>> >  >   private MyRepositorySelector() {
 >>> >  >   }
 >>> >  >
 >>> >  >   public LoggerRepository getLoggerRepository() {
 >>> >  >      ClassLoader loader =
 >>> > Thread.currentThread().getContextClassLoader();
 >>> >  >      LoggerRepository repository =
 >>> >  >(LoggerRepository)repositories.get(loader);
 >>> >  >
 >>> >  >      if (repository == null) {
 >>> >  >          return defaultRepository;
 >>> >  >      } else {
 >>> >  >          return repository;
 >>> >  >      }
 >>> >  >   }
 >>> >  >}
 >>> >  >--
 >>> >  >View this message in context:
 >>> >
 >>> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
 >>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>> >  >
 >>> >  >
 >>> >  >---------------------------------------------------------------------
 >>> >  >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 this message in context:
 >>>
 >>
 >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
 >>> Sent from the Log4j - Users mailing list archive at Nabble.com.
 >>>
 >>>
 >>> ---------------------------------------------------------------------
 >>> 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 this message in context:
 >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
 >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
 >Sent from the Log4j - Users mailing list archive at Nabble.com.
 >
 >
 >---------------------------------------------------------------------
 >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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by sohan <so...@mms.gov>.
"What do you mean "'pcs' is the log file name"?  That would be the logger
name,
not the file name."
My mistake, I meant to say that it is both the logger name as well as I
named the log file name same too after the application name.
 I tried with both LogFactory of commons-logging as well as direct use of
Log4j. Behavior is the same
I did notice one thing, Log information is being written normally from java
classes that extend HttpServlet.
Logging from other java class files is not working as intended. My
application uses struts 1.2.9 too.

thanks,
Sohan


Jacob Kjome wrote:
> 
> Quoting sohan <so...@mms.gov>:
> 
>>
>> I changed to use Log4j.xml from Log4j.properties and also changed to
>> non-static loggers and with in the static methods followed the link
>> examples. Now the logging is taking place only for the loggers mentioned
>> in
>> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the log
>> file
>> name.
>>
> 
> What do you mean "'pcs' is the log file name"?  That would be the logger
> name,
> not the file name.
> 
> Also, I didn't mean to direct you to use commons-logging.  If you were
> using
> log4j directly, please keep using it.  In fact, log wrappers like SLF4J
> and
> commons-logging have issues when it comes to repository selectors.  Search
> the
> SLF4J user list for details on this.  There's also a bug in the SLF4J
> database
> about this.  I believe the same applies to commons-logging.  Log4j cannot
> guarantee proper logging separation when you use a wrapper.
> 
>> Any idea as to why the non static logger is not working!
>>
> 
> I would guess it's because you are using commons-logging.  Use Log4j
> directly,
> just as you were previously.  I only sent you the commons-logging link
> because
> they had a good synopsis of the static logger issue, not to convince you
> to
> move to commons-logging.
> 
> 
> Jake
> 
>> thanks,
>> Sohan
>>
>>
>> Jacob Kjome wrote:
>> >
>> >
>> > 1.  Use non-static loggers (for Serializable classes, you'll need to
>> > mark these as transient)
>> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
>> > selectors.  There's already one written for Log4j-1.3alpha.  Even if
>> > you don't care to use 1.3, you can use it to get an idea of how to
>> > write one for 1.2.
>> >
>> >
>> > See:
>> > http://www.qos.ch/logging/sc.jsp
>> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>> >
>> >
>> > Jake
>> >
>> > At 03:09 PM 4/9/2007, you wrote:
>> >  >
>> >  >I followed some examples on the web to use RepositorySelector to
>> > implement
>> >  >separate logging for 2 applications deployed on the same instance of
>> >  >weblogic server. I have the Lgo4j.properties file under Web-Inf/
>> folder,
>> >  >This is loaded through web.xml file through a startup servlet.
>> Problem
>> > is
>> >  >logging is taking place either in Log4j.log file or other
>> applications
>> > log
>> >  >file. In each java class file, I use..
>> >  >       private static Logger log =
>> Logger.getLogger(LoginFilter.class);
>> >  >and call the log .info ..accordingly. In log4j properties file, only
>> >  >difference is file name for 2 applications.
>> >  >
>> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
>> >  >
>> >  >thanks for the help
>> >  >Sohan
>> >  >
>> >  >web.xml entry...
>> >  >
>> >  >       <servlet>
>> >  >               <servlet-name>log4j-init</servlet-name>
>> >  >              
>> <servlet-class>pcs.common.util.Log4jInit</servlet-class>
>> >  >           <init-param>
>> >  >                   <param-name>Log4JProperties</param-name>
>> >  >
>> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
>> >  >           </init-param>
>> >  >           <init-param>
>> >  >                   <param-name>LogToFileOnly</param-name>
>> >  >                   <param-value>false</param-value>
>> >  >           </init-param>
>> >  >               <load-on-startup>1</load-on-startup>
>> >  >       </servlet>
>> >  >
>> >  >public class Log4jInit extends HttpServlet {
>> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
>> >  >       public void init() throws ServletException {
>> >  >
>> > System.out.println("\n\n---------------Log4jInit---------------\n\n");
>> >
>> >  >               MyRepositorySelector.init(this.getServletConfig());
>> >  >               Logger log = Logger.getLogger(this.getClass());
>> >  >               log.info("Log message from Log4jInit servlet");
>> >  >               System.out.println("\n\n---------------Log4jInit:
>> >  >Complete---------------\n\n");
>> >  >
>> >  >       }
>> >  >
>> >  >}
>> >  >
>> >  >public class MyRepositorySelector implements RepositorySelector
>> >  >{
>> >  >   private static boolean initialized = false;
>> >  >   private static Object guard = LogManager.getRootLogger();
>> >  >
>> >  >   private static Map repositories = new HashMap();
>> >  >   private static LoggerRepository defaultRepository;
>> >  >
>> >  >   public static synchronized void init(ServletConfig config)
>> >  >        throws ServletException {
>> >  >      if( !initialized ) // set the global RepositorySelector
>> >  >      {
>> >  >         defaultRepository = LogManager.getLoggerRepository();
>> >  >         RepositorySelector theSelector = new MyRepositorySelector();
>> >  >         LogManager.setRepositorySelector(theSelector, guard);
>> >  >         initialized = true;
>> >  >      }
>> >  >
>> >  >      Hierarchy hierarchy = new Hierarchy(new
>> > RootCategory(Level.DEBUG));
>> >  >      loadLog4JConfig(config, hierarchy);
>> >  >      ClassLoader loader =
>> > Thread.currentThread().getContextClassLoader();
>> >  >      repositories.put(loader, hierarchy);
>> >  >   }
>> >  >
>> >  >   public static synchronized void removeFromRepository() {
>> >  >
>> > repositories.remove(Thread.currentThread().getContextClassLoader());
>> >  >   }
>> >  >
>> >  >
>> >  >   private static void loadLog4JConfig(ServletConfig config,
>> >  >                                       Hierarchy hierarchy)
>> >  >                                            throws ServletException {
>> >  >        try {
>> >  >
>> >  >               String strLogProperties =
>> >  >
>> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
>> >  >               System.out.println("strLogProperties: " +
>> > strLogProperties);
>> >  >               Properties logProperties = new Properties();
>> >  >               try {
>> >  >
>> > 
>> >logProperties.load(config.getServletContext().getResourceAsStream(strL
>> >  >ogProperties));
>> >  >               } catch (Exception e) {
>> >  >                       System.out.println("ERROR: Loading log4j
>> > properties: " +
>> >  >e.getMessage());
>> >  >                       //e.printStackTrace();
>> >  >               }
>> >  >               PropertyConfigurator propConf = new
>> > PropertyConfigurator();
>> >  >            propConf.doConfigure(logProperties, hierarchy);
>> >  >                       } catch (Exception e) {
>> >  >            throw new ServletException(e);
>> >  >        }
>> >  >    }
>> >  >
>> >  >   private MyRepositorySelector() {
>> >  >   }
>> >  >
>> >  >   public LoggerRepository getLoggerRepository() {
>> >  >      ClassLoader loader =
>> > Thread.currentThread().getContextClassLoader();
>> >  >      LoggerRepository repository =
>> >  >(LoggerRepository)repositories.get(loader);
>> >  >
>> >  >      if (repository == null) {
>> >  >          return defaultRepository;
>> >  >      } else {
>> >  >          return repository;
>> >  >      }
>> >  >   }
>> >  >}
>> >  >--
>> >  >View this message in context:
>> > 
>> >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
>> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>> >  >
>> >  >
>> >  >---------------------------------------------------------------------
>> >  >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 this message in context:
>>
> http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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 this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9931051
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by Jacob Kjome <ho...@visi.com>.
Quoting sohan <so...@mms.gov>:

>
> I changed to use Log4j.xml from Log4j.properties and also changed to
> non-static loggers and with in the static methods followed the link
> examples. Now the logging is taking place only for the loggers mentioned in
> the static methods, Log log = LogFactory.getLog("pcs"); pcs is the log file
> name.
>

What do you mean "'pcs' is the log file name"?  That would be the logger name,
not the file name.

Also, I didn't mean to direct you to use commons-logging.  If you were using
log4j directly, please keep using it.  In fact, log wrappers like SLF4J and
commons-logging have issues when it comes to repository selectors.  Search the
SLF4J user list for details on this.  There's also a bug in the SLF4J database
about this.  I believe the same applies to commons-logging.  Log4j cannot
guarantee proper logging separation when you use a wrapper.

> Any idea as to why the non static logger is not working!
>

I would guess it's because you are using commons-logging.  Use Log4j directly,
just as you were previously.  I only sent you the commons-logging link because
they had a good synopsis of the static logger issue, not to convince you to
move to commons-logging.


Jake

> thanks,
> Sohan
>
>
> Jacob Kjome wrote:
> >
> >
> > 1.  Use non-static loggers (for Serializable classes, you'll need to
> > mark these as transient)
> > 2.  Avoid Classloader-based repository selectors.  Use JNDI-base
> > selectors.  There's already one written for Log4j-1.3alpha.  Even if
> > you don't care to use 1.3, you can use it to get an idea of how to
> > write one for 1.2.
> >
> >
> > See:
> > http://www.qos.ch/logging/sc.jsp
> > http://wiki.apache.org/jakarta-commons/Logging/StaticLog
> >
> >
> > Jake
> >
> > At 03:09 PM 4/9/2007, you wrote:
> >  >
> >  >I followed some examples on the web to use RepositorySelector to
> > implement
> >  >separate logging for 2 applications deployed on the same instance of
> >  >weblogic server. I have the Lgo4j.properties file under Web-Inf/ folder,
> >  >This is loaded through web.xml file through a startup servlet. Problem
> > is
> >  >logging is taking place either in Log4j.log file or other applications
> > log
> >  >file. In each java class file, I use..
> >  >       private static Logger log = Logger.getLogger(LoginFilter.class);
> >  >and call the log .info ..accordingly. In log4j properties file, only
> >  >difference is file name for 2 applications.
> >  >
> >  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
> >  >
> >  >thanks for the help
> >  >Sohan
> >  >
> >  >web.xml entry...
> >  >
> >  >       <servlet>
> >  >               <servlet-name>log4j-init</servlet-name>
> >  >               <servlet-class>pcs.common.util.Log4jInit</servlet-class>
> >  >           <init-param>
> >  >                   <param-name>Log4JProperties</param-name>
> >  >
> > <param-value>/WEB-INF/log4j-dev.properties</param-value>
> >  >           </init-param>
> >  >           <init-param>
> >  >                   <param-name>LogToFileOnly</param-name>
> >  >                   <param-value>false</param-value>
> >  >           </init-param>
> >  >               <load-on-startup>1</load-on-startup>
> >  >       </servlet>
> >  >
> >  >public class Log4jInit extends HttpServlet {
> >  >       static Logger log = Logger.getLogger(Log4jInit.class);
> >  >       public void init() throws ServletException {
> >  >
> > System.out.println("\n\n---------------Log4jInit---------------\n\n");
> >
> >  >               MyRepositorySelector.init(this.getServletConfig());
> >  >               Logger log = Logger.getLogger(this.getClass());
> >  >               log.info("Log message from Log4jInit servlet");
> >  >               System.out.println("\n\n---------------Log4jInit:
> >  >Complete---------------\n\n");
> >  >
> >  >       }
> >  >
> >  >}
> >  >
> >  >public class MyRepositorySelector implements RepositorySelector
> >  >{
> >  >   private static boolean initialized = false;
> >  >   private static Object guard = LogManager.getRootLogger();
> >  >
> >  >   private static Map repositories = new HashMap();
> >  >   private static LoggerRepository defaultRepository;
> >  >
> >  >   public static synchronized void init(ServletConfig config)
> >  >        throws ServletException {
> >  >      if( !initialized ) // set the global RepositorySelector
> >  >      {
> >  >         defaultRepository = LogManager.getLoggerRepository();
> >  >         RepositorySelector theSelector = new MyRepositorySelector();
> >  >         LogManager.setRepositorySelector(theSelector, guard);
> >  >         initialized = true;
> >  >      }
> >  >
> >  >      Hierarchy hierarchy = new Hierarchy(new
> > RootCategory(Level.DEBUG));
> >  >      loadLog4JConfig(config, hierarchy);
> >  >      ClassLoader loader =
> > Thread.currentThread().getContextClassLoader();
> >  >      repositories.put(loader, hierarchy);
> >  >   }
> >  >
> >  >   public static synchronized void removeFromRepository() {
> >  >
> > repositories.remove(Thread.currentThread().getContextClassLoader());
> >  >   }
> >  >
> >  >
> >  >   private static void loadLog4JConfig(ServletConfig config,
> >  >                                       Hierarchy hierarchy)
> >  >                                            throws ServletException {
> >  >        try {
> >  >
> >  >               String strLogProperties =
> >  >
> > config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
> >  >               System.out.println("strLogProperties: " +
> > strLogProperties);
> >  >               Properties logProperties = new Properties();
> >  >               try {
> >  >
> >  >logProperties.load(config.getServletContext().getResourceAsStream(strL
> >  >ogProperties));
> >  >               } catch (Exception e) {
> >  >                       System.out.println("ERROR: Loading log4j
> > properties: " +
> >  >e.getMessage());
> >  >                       //e.printStackTrace();
> >  >               }
> >  >               PropertyConfigurator propConf = new
> > PropertyConfigurator();
> >  >            propConf.doConfigure(logProperties, hierarchy);
> >  >                       } catch (Exception e) {
> >  >            throw new ServletException(e);
> >  >        }
> >  >    }
> >  >
> >  >   private MyRepositorySelector() {
> >  >   }
> >  >
> >  >   public LoggerRepository getLoggerRepository() {
> >  >      ClassLoader loader =
> > Thread.currentThread().getContextClassLoader();
> >  >      LoggerRepository repository =
> >  >(LoggerRepository)repositories.get(loader);
> >  >
> >  >      if (repository == null) {
> >  >          return defaultRepository;
> >  >      } else {
> >  >          return repository;
> >  >      }
> >  >   }
> >  >}
> >  >--
> >  >View this message in context:
> >  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
> >  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
> >  >Sent from the Log4j - Users mailing list archive at Nabble.com.
> >  >
> >  >
> >  >---------------------------------------------------------------------
> >  >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 this message in context:
>
http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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


Re: separate log files for application's on weblogic with log4j using RepositorySelector

Posted by sohan <so...@mms.gov>.
I changed to use Log4j.xml from Log4j.properties and also changed to
non-static loggers and with in the static methods followed the link
examples. Now the logging is taking place only for the loggers mentioned in
the static methods, Log log = LogFactory.getLog("pcs"); pcs is the log file
name. 

Any idea as to why the non static logger is not working!

thanks,
Sohan


Jacob Kjome wrote:
> 
> 
> 1.  Use non-static loggers (for Serializable classes, you'll need to 
> mark these as transient)
> 2.  Avoid Classloader-based repository selectors.  Use JNDI-base 
> selectors.  There's already one written for Log4j-1.3alpha.  Even if 
> you don't care to use 1.3, you can use it to get an idea of how to 
> write one for 1.2.
> 
> 
> See:
> http://www.qos.ch/logging/sc.jsp
> http://wiki.apache.org/jakarta-commons/Logging/StaticLog
> 
> 
> Jake
> 
> At 03:09 PM 4/9/2007, you wrote:
>  >
>  >I followed some examples on the web to use RepositorySelector to
> implement
>  >separate logging for 2 applications deployed on the same instance of
>  >weblogic server. I have the Lgo4j.properties file under Web-Inf/ folder,
>  >This is loaded through web.xml file through a startup servlet. Problem
> is
>  >logging is taking place either in Log4j.log file or other applications
> log
>  >file. In each java class file, I use..
>  >       private static Logger log = Logger.getLogger(LoginFilter.class);
>  >and call the log .info ..accordingly. In log4j properties file, only
>  >difference is file name for 2 applications.
>  >
>  >I am using weblogic 8.1.6 and Log4j 1.2.8 versions
>  >
>  >thanks for the help
>  >Sohan
>  >
>  >web.xml entry...
>  >
>  >       <servlet>
>  >               <servlet-name>log4j-init</servlet-name>
>  >               <servlet-class>pcs.common.util.Log4jInit</servlet-class>
>  >           <init-param>
>  >                   <param-name>Log4JProperties</param-name>
>  >                  
> <param-value>/WEB-INF/log4j-dev.properties</param-value>
>  >           </init-param>
>  >           <init-param>
>  >                   <param-name>LogToFileOnly</param-name>
>  >                   <param-value>false</param-value>
>  >           </init-param>
>  >               <load-on-startup>1</load-on-startup>
>  >       </servlet>
>  >
>  >public class Log4jInit extends HttpServlet {
>  >       static Logger log = Logger.getLogger(Log4jInit.class);
>  >       public void init() throws ServletException {
>  > 
> System.out.println("\n\n---------------Log4jInit---------------\n\n"); 
> 
>  >               MyRepositorySelector.init(this.getServletConfig());
>  >               Logger log = Logger.getLogger(this.getClass());
>  >               log.info("Log message from Log4jInit servlet");
>  >               System.out.println("\n\n---------------Log4jInit:
>  >Complete---------------\n\n");
>  >
>  >       }
>  >
>  >}
>  >
>  >public class MyRepositorySelector implements RepositorySelector
>  >{
>  >   private static boolean initialized = false;
>  >   private static Object guard = LogManager.getRootLogger();
>  >
>  >   private static Map repositories = new HashMap();
>  >   private static LoggerRepository defaultRepository;
>  >
>  >   public static synchronized void init(ServletConfig config)
>  >        throws ServletException {
>  >      if( !initialized ) // set the global RepositorySelector
>  >      {
>  >         defaultRepository = LogManager.getLoggerRepository();
>  >         RepositorySelector theSelector = new MyRepositorySelector();
>  >         LogManager.setRepositorySelector(theSelector, guard);
>  >         initialized = true;
>  >      }
>  >
>  >      Hierarchy hierarchy = new Hierarchy(new
> RootCategory(Level.DEBUG));
>  >      loadLog4JConfig(config, hierarchy);
>  >      ClassLoader loader =
> Thread.currentThread().getContextClassLoader();
>  >      repositories.put(loader, hierarchy);
>  >   }
>  >
>  >   public static synchronized void removeFromRepository() {
>  >      
> repositories.remove(Thread.currentThread().getContextClassLoader());
>  >   }
>  >
>  >
>  >   private static void loadLog4JConfig(ServletConfig config,
>  >                                       Hierarchy hierarchy)
>  >                                            throws ServletException {
>  >        try {
>  >
>  >               String strLogProperties =
>  > 
> config.getInitParameter(GlobalDictionary.LOG_PROPERTIES);
>  >               System.out.println("strLogProperties: " +
> strLogProperties);
>  >               Properties logProperties = new Properties();
>  >               try {
>  >
>  >logProperties.load(config.getServletContext().getResourceAsStream(strL
>  >ogProperties));
>  >               } catch (Exception e) {
>  >                       System.out.println("ERROR: Loading log4j 
> properties: " +
>  >e.getMessage());
>  >                       //e.printStackTrace();
>  >               }
>  >               PropertyConfigurator propConf = new
> PropertyConfigurator();
>  >            propConf.doConfigure(logProperties, hierarchy);
>  >                       } catch (Exception e) {
>  >            throw new ServletException(e);
>  >        }
>  >    }
>  >
>  >   private MyRepositorySelector() {
>  >   }
>  >
>  >   public LoggerRepository getLoggerRepository() {
>  >      ClassLoader loader =
> Thread.currentThread().getContextClassLoader();
>  >      LoggerRepository repository =
>  >(LoggerRepository)repositories.get(loader);
>  >
>  >      if (repository == null) {
>  >          return defaultRepository;
>  >      } else {
>  >          return repository;
>  >      }
>  >   }
>  >}
>  >--
>  >View this message in context:
>  >http://www.nabble.com/separate-log-files-for-application%27s-on-weblog
>  >ic-with-log4j-using-RepositorySelector-tf3549324.html#a9908677
>  >Sent from the Log4j - Users mailing list archive at Nabble.com.
>  >
>  >
>  >---------------------------------------------------------------------
>  >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 this message in context: http://www.nabble.com/separate-log-files-for-application%27s-on-weblogic-with-log4j-using-RepositorySelector-tf3549324.html#a9926589
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


RE: Updating Wrong File

Posted by Jacob Kjome <ho...@visi.com>.
Quoting "Eric.Wolf@bcbsks.com" <Er...@bcbsks.com>:
>
> It sounds like it would be easier to change over to child-first class
> loading.  Is that bad in Weblogic?
>

I'm not sure whether or not it would be bad?  However, in my experience, the
default behavior is likely to work a bit better than optional stuff since the
default behavior is far better tested, not only by Weblogic themselves but by
their users.

Check the Weblogic docs on how to enable child-first, or parent-last,
classloading.  You can try it out.  If nothing breaks, you're golden.  If
something breaks, try using a repository selector based on JNDI.  See another
thread on the user list for an explanation of how to use the one in Log4j-1.3
(though I'm not advocating moving permanently to 1.3, only to try it out to see
if the ContextJNDISelector works.  Then you can modify it to work for 1.2).

Jake

> Eric Wolf
>
>
> Jacob Kjome <ho...@visi.com> wrote on 04/11/2007 09:54:39 AM:
>
> >
> > Weblogic does not implement child-first classloading by default.  This
> means
> > that if there is a log4j.jar in the server classpath, or even in the EAR
> > containing one more more WARS (with each WAR having it's own log4j.jar),
> the
> > log4j.jar in the parent classloader will be used instead of the one in
> > WEB-INF/lib.
> >
> > Your only recourse in this situation is to use a repository selector.
> >
> > Jake
> >
> > Quoting Prashant Saraf <ps...@cctc.com>:
> >
> > > I did that still not working...
> > >
> > >
> > > Thanks and Regards
> > > प्रशांत सराफ
> > > (Prashant Saraf)
> > > SE-I
> > > Cross Country Infotech
> > > Ext : 72543
> > > -----Original Message-----
> > > From: Eric.Wolf@bcbsks.com [mailto:Eric.Wolf@bcbsks.com]
> > > Sent: Tuesday, April 10, 2007 9:50 PM
> > > To: Log4J Users List
> > > Subject: Re: Updating Wrong File
> > >
> > >
> > >
> > >
> > >
> > > Try putting the log4j JAR file in each of the application's WEB-INF/lib
> > > directory so each application will have its own version to initialize.
> I
> > > ran into this when I tried to put the log4j JAR file in a shared
> library
> > > and another application got "confused" on where to log.  I put it back
> in
> > > my application and it has been fine.
> > >
> > > Eric Wolf
> > >
> > >
> > >
> > >
> > >              "Prashant Saraf"
> > >              <ps...@cctc.com>
> > >
> To
> > >              04/10/2007 12:53          "Log4J Users List"
> > >              AM                        <lo...@logging.apache.org>
> > >
> cc
> > >
> > >              Please respond to
> Topic
> > >                "Log4J Users
> > >                    List"
> Subject
> > >              <log4j-user@loggi         Updating Wrong File
> > >               ng.apache.org>
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Hi all I am new to Log4j.
> > >
> > >                   I had an issue. I am using Weblogic 8.1, I had two
> > > application both had their log4j File. Now what is happing is
> > > applicationA  is running properly with log4j. When I hit ApplicationB
> it
> > > also works proper, Now when I hit applicationA it show me logged in
> > > ApplicationB
> > >
> > >
> > >
> > > ApplicationA log4j properties file
> > >
> > >
> > >
> > > # Set root logger level to DEBUG and its only appender to A1.
> > >
> > > log4j.rootLogger=WARN,A1, F1
> > >
> > >
> > >
> > > log4j.category.org.apache.struts=WARN
> > >
> > > log4j.category.org.apache.commons.logging=WARN
> > >
> > > log4j.category. APPA =DEBUG
> > >
> > > # A1 is set to be a ConsoleAppender.
> > >
> > > log4j.appender.A1=org.apache.log4j.ConsoleAppender
> > >
> > > # A1 uses PatternLayout.
> > >
> > > log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> > >
> > > #log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n
> > >
> > > log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
> > > %m%n
> > >
> > > # F1 is set to be a FileAppender.
> > >
> > > log4j.appender.F1=org.apache.log4j.RollingFileAppender
> > >
> > > log4j.appender.F1.file=c:/logs/APPA.log
> > >
> > > log4j.appender.F1.MaxFileSize=10000KB
> > >
> > > log4j.appender.F1.MaxBackupIndex=5
> > >
> > > # F1 uses PatternLayout.
> > >
> > > log4j.appender.F1.layout=org.apache.log4j.PatternLayout
> > >
> > > #log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n
> > >
> > > log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n
> > >
> > >
> > >
> > > ApplicationB log4j properties file
> > >
> > > # ***** Set root logger level to ERROR and its two appenders to stdout
> > > and R.
> > >
> > > log4j.rootLogger=debug, R
> > >
> > >
> > >
> > > # ***** stdout is set to be a ConsoleAppender.
> > >
> > > log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> > >
> > > # ***** stdout uses PatternLayout.
> > >
> > > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> > >
> > > # ***** Pattern to output the caller's file name and line number.
> > >
> > > log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
> > >
> > >
> > >
> > > log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> > >
> > > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> > >
> > >
> > >
> > > # ***** R is set to be a RollingFileAppender.
> > >
> > > log4j.appender.R=org.apache.log4j.RollingFileAppender
> > >
> > > log4j.appender.R.File=c:/logs/APPB.log
> > >
> > > # ***** Max file size is set to 10000KB
> > >
> > > log4j.appender.R.MaxFileSize=10000KB
> > >
> > > # ***** Keep one backup file
> > >
> > > log4j.appender.R.MaxBackupIndex=1
> > >
> > > # ***** R uses PatternLayout.
> > >
> > > log4j.appender.R.layout=org.apache.log4j.PatternLayout
> > >
> > > log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p
> -
> > > %m%n
> > >
> > >
> > >
> > > # Set Struts/Commons log level
> > >
> > > log4j.logger.org.apache.struts=WARN
> > >
> > > log4j.logger.org.apache.commons=WARN
> > >
> > > Thanks and Regards
> > > Prashant Saraf
> > >
> > > ---------------------------------------------------------------------
> > > 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
> > >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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


RE: Updating Wrong File

Posted by Er...@bcbsks.com.



It sounds like it would be easier to change over to child-first class
loading.  Is that bad in Weblogic?

Eric Wolf


Jacob Kjome <ho...@visi.com> wrote on 04/11/2007 09:54:39 AM:

>
> Weblogic does not implement child-first classloading by default.  This
means
> that if there is a log4j.jar in the server classpath, or even in the EAR
> containing one more more WARS (with each WAR having it's own log4j.jar),
the
> log4j.jar in the parent classloader will be used instead of the one in
> WEB-INF/lib.
>
> Your only recourse in this situation is to use a repository selector.
>
> Jake
>
> Quoting Prashant Saraf <ps...@cctc.com>:
>
> > I did that still not working...
> >
> >
> > Thanks and Regards
> > प्रशांत सराफ
> > (Prashant Saraf)
> > SE-I
> > Cross Country Infotech
> > Ext : 72543
> > -----Original Message-----
> > From: Eric.Wolf@bcbsks.com [mailto:Eric.Wolf@bcbsks.com]
> > Sent: Tuesday, April 10, 2007 9:50 PM
> > To: Log4J Users List
> > Subject: Re: Updating Wrong File
> >
> >
> >
> >
> >
> > Try putting the log4j JAR file in each of the application's WEB-INF/lib
> > directory so each application will have its own version to initialize.
I
> > ran into this when I tried to put the log4j JAR file in a shared
library
> > and another application got "confused" on where to log.  I put it back
in
> > my application and it has been fine.
> >
> > Eric Wolf
> >
> >
> >
> >
> >              "Prashant Saraf"
> >              <ps...@cctc.com>
> >
To
> >              04/10/2007 12:53          "Log4J Users List"
> >              AM                        <lo...@logging.apache.org>
> >
cc
> >
> >              Please respond to
Topic
> >                "Log4J Users
> >                    List"
Subject
> >              <log4j-user@loggi         Updating Wrong File
> >               ng.apache.org>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Hi all I am new to Log4j.
> >
> >                   I had an issue. I am using Weblogic 8.1, I had two
> > application both had their log4j File. Now what is happing is
> > applicationA  is running properly with log4j. When I hit ApplicationB
it
> > also works proper, Now when I hit applicationA it show me logged in
> > ApplicationB
> >
> >
> >
> > ApplicationA log4j properties file
> >
> >
> >
> > # Set root logger level to DEBUG and its only appender to A1.
> >
> > log4j.rootLogger=WARN,A1, F1
> >
> >
> >
> > log4j.category.org.apache.struts=WARN
> >
> > log4j.category.org.apache.commons.logging=WARN
> >
> > log4j.category. APPA =DEBUG
> >
> > # A1 is set to be a ConsoleAppender.
> >
> > log4j.appender.A1=org.apache.log4j.ConsoleAppender
> >
> > # A1 uses PatternLayout.
> >
> > log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> >
> > #log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n
> >
> > log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
> > %m%n
> >
> > # F1 is set to be a FileAppender.
> >
> > log4j.appender.F1=org.apache.log4j.RollingFileAppender
> >
> > log4j.appender.F1.file=c:/logs/APPA.log
> >
> > log4j.appender.F1.MaxFileSize=10000KB
> >
> > log4j.appender.F1.MaxBackupIndex=5
> >
> > # F1 uses PatternLayout.
> >
> > log4j.appender.F1.layout=org.apache.log4j.PatternLayout
> >
> > #log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n
> >
> > log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n
> >
> >
> >
> > ApplicationB log4j properties file
> >
> > # ***** Set root logger level to ERROR and its two appenders to stdout
> > and R.
> >
> > log4j.rootLogger=debug, R
> >
> >
> >
> > # ***** stdout is set to be a ConsoleAppender.
> >
> > log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> >
> > # ***** stdout uses PatternLayout.
> >
> > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> >
> > # ***** Pattern to output the caller's file name and line number.
> >
> > log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
> >
> >
> >
> > log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> >
> > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> >
> >
> >
> > # ***** R is set to be a RollingFileAppender.
> >
> > log4j.appender.R=org.apache.log4j.RollingFileAppender
> >
> > log4j.appender.R.File=c:/logs/APPB.log
> >
> > # ***** Max file size is set to 10000KB
> >
> > log4j.appender.R.MaxFileSize=10000KB
> >
> > # ***** Keep one backup file
> >
> > log4j.appender.R.MaxBackupIndex=1
> >
> > # ***** R uses PatternLayout.
> >
> > log4j.appender.R.layout=org.apache.log4j.PatternLayout
> >
> > log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p
-
> > %m%n
> >
> >
> >
> > # Set Struts/Commons log level
> >
> > log4j.logger.org.apache.struts=WARN
> >
> > log4j.logger.org.apache.commons=WARN
> >
> > Thanks and Regards
> > Prashant Saraf
> >
> > ---------------------------------------------------------------------
> > 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
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

RE: Updating Wrong File

Posted by Jacob Kjome <ho...@visi.com>.
Weblogic does not implement child-first classloading by default.  This means
that if there is a log4j.jar in the server classpath, or even in the EAR
containing one more more WARS (with each WAR having it's own log4j.jar), the
log4j.jar in the parent classloader will be used instead of the one in
WEB-INF/lib.

Your only recourse in this situation is to use a repository selector.

Jake

Quoting Prashant Saraf <ps...@cctc.com>:

> I did that still not working...
>
>
> Thanks and Regards
> प्रशांत सराफ
> (Prashant Saraf)
> SE-I
> Cross Country Infotech
> Ext : 72543
> -----Original Message-----
> From: Eric.Wolf@bcbsks.com [mailto:Eric.Wolf@bcbsks.com]
> Sent: Tuesday, April 10, 2007 9:50 PM
> To: Log4J Users List
> Subject: Re: Updating Wrong File
>
>
>
>
>
> Try putting the log4j JAR file in each of the application's WEB-INF/lib
> directory so each application will have its own version to initialize.  I
> ran into this when I tried to put the log4j JAR file in a shared library
> and another application got "confused" on where to log.  I put it back in
> my application and it has been fine.
>
> Eric Wolf
>
>
>
>
>              "Prashant Saraf"
>              <ps...@cctc.com>
>                                                                         To
>              04/10/2007 12:53          "Log4J Users List"
>              AM                        <lo...@logging.apache.org>
>                                                                         cc
>
>              Please respond to                                       Topic
>                "Log4J Users
>                    List"                                           Subject
>              <log4j-user@loggi         Updating Wrong File
>               ng.apache.org>
>
>
>
>
>
>
>
>
>
> Hi all I am new to Log4j.
>
>                   I had an issue. I am using Weblogic 8.1, I had two
> application both had their log4j File. Now what is happing is
> applicationA  is running properly with log4j. When I hit ApplicationB it
> also works proper, Now when I hit applicationA it show me logged in
> ApplicationB
>
>
>
> ApplicationA log4j properties file
>
>
>
> # Set root logger level to DEBUG and its only appender to A1.
>
> log4j.rootLogger=WARN,A1, F1
>
>
>
> log4j.category.org.apache.struts=WARN
>
> log4j.category.org.apache.commons.logging=WARN
>
> log4j.category. APPA =DEBUG
>
> # A1 is set to be a ConsoleAppender.
>
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
>
> # A1 uses PatternLayout.
>
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
>
> #log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n
>
> log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
> %m%n
>
> # F1 is set to be a FileAppender.
>
> log4j.appender.F1=org.apache.log4j.RollingFileAppender
>
> log4j.appender.F1.file=c:/logs/APPA.log
>
> log4j.appender.F1.MaxFileSize=10000KB
>
> log4j.appender.F1.MaxBackupIndex=5
>
> # F1 uses PatternLayout.
>
> log4j.appender.F1.layout=org.apache.log4j.PatternLayout
>
> #log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n
>
> log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n
>
>
>
> ApplicationB log4j properties file
>
> # ***** Set root logger level to ERROR and its two appenders to stdout
> and R.
>
> log4j.rootLogger=debug, R
>
>
>
> # ***** stdout is set to be a ConsoleAppender.
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>
> # ***** stdout uses PatternLayout.
>
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>
> # ***** Pattern to output the caller's file name and line number.
>
> log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
>
>
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>
>
>
> # ***** R is set to be a RollingFileAppender.
>
> log4j.appender.R=org.apache.log4j.RollingFileAppender
>
> log4j.appender.R.File=c:/logs/APPB.log
>
> # ***** Max file size is set to 10000KB
>
> log4j.appender.R.MaxFileSize=10000KB
>
> # ***** Keep one backup file
>
> log4j.appender.R.MaxBackupIndex=1
>
> # ***** R uses PatternLayout.
>
> log4j.appender.R.layout=org.apache.log4j.PatternLayout
>
> log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p -
> %m%n
>
>
>
> # Set Struts/Commons log level
>
> log4j.logger.org.apache.struts=WARN
>
> log4j.logger.org.apache.commons=WARN
>
> Thanks and Regards
> Prashant Saraf
>
> ---------------------------------------------------------------------
> 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
>




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


RE: Updating Wrong File

Posted by Er...@bcbsks.com.



I have not seen the below 2 lines in Log4j.  I didn't know some Struts
classes were for Log4j.

log4j.category.org.apache.struts=WARN
log4j.category.org.apache.commons.logging=WARN

Below is a piece of my config file that works.

log4j.rootLogger=debug, CONSOLE, ROLLING

# CONSOLE is set to be a ConsoleAppender which outputs to the web server
console
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%n### KIDS
[%d{ISO8601}]%8.8p: %30.50c{6} -- %x%n  ### Log Message: %m%n

# ROLLING is a RollingFileAppender that outputs to a rolling log file
called kids_rolling_log
log4j.appender.ROLLING=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLING.File=
/apps/ln003dv/server1/kids/logs/kids_rolling_log
log4j.appender.ROLLING.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLING.layout.ConversionPattern=[%d{ISO8601}]%8.8p: %30.36
c{4} -- %x%n  ### Log Message: %m%n

# Set the max size of the file, the number of backup files and logging
threshold
log4j.appender.ROLLING.MaxFileSize=10MB
log4j.appender.ROLLING.MaxBackupIndex=10
log4j.appender.ROLLING.Threshold=DEBUG

Hope this helps,
Eric Wolf


"Prashant Saraf" <ps...@cctc.com> wrote on 04/11/2007 06:19:35 AM:

> I did that still not working...
>
>
> Thanks and Regards
> प्रशांत सराफ
> (Prashant Saraf)
> SE-I
> Cross Country Infotech
> Ext : 72543
> -----Original Message-----
> From: Eric.Wolf@bcbsks.com [mailto:Eric.Wolf@bcbsks.com]
> Sent: Tuesday, April 10, 2007 9:50 PM
> To: Log4J Users List
> Subject: Re: Updating Wrong File
>
>
>
>
>
> Try putting the log4j JAR file in each of the application's WEB-INF/lib
> directory so each application will have its own version to initialize.  I
> ran into this when I tried to put the log4j JAR file in a shared library
> and another application got "confused" on where to log.  I put it back in
> my application and it has been fine.
>
> Eric Wolf
>
>
>
>

>              "Prashant Saraf"

>              <ps...@cctc.com>

>
To
>              04/10/2007 12:53          "Log4J Users List"

>              AM                        <lo...@logging.apache.org>

>
cc
>

>              Please respond to
Topic
>                "Log4J Users

>                    List"
Subject
>              <log4j-user@loggi         Updating Wrong File

>               ng.apache.org>

>

>

>

>

>

>
>
>
>
> Hi all I am new to Log4j.
>
>                   I had an issue. I am using Weblogic 8.1, I had two
> application both had their log4j File. Now what is happing is
> applicationA  is running properly with log4j. When I hit ApplicationB it
> also works proper, Now when I hit applicationA it show me logged in
> ApplicationB
>
>
>
> ApplicationA log4j properties file
>
>
>
> # Set root logger level to DEBUG and its only appender to A1.
>
> log4j.rootLogger=WARN,A1, F1
>
>
>
> log4j.category.org.apache.struts=WARN
>
> log4j.category.org.apache.commons.logging=WARN
>
> log4j.category. APPA =DEBUG
>
> # A1 is set to be a ConsoleAppender.
>
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
>
> # A1 uses PatternLayout.
>
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
>
> #log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n
>
> log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
> %m%n
>
> # F1 is set to be a FileAppender.
>
> log4j.appender.F1=org.apache.log4j.RollingFileAppender
>
> log4j.appender.F1.file=c:/logs/APPA.log
>
> log4j.appender.F1.MaxFileSize=10000KB
>
> log4j.appender.F1.MaxBackupIndex=5
>
> # F1 uses PatternLayout.
>
> log4j.appender.F1.layout=org.apache.log4j.PatternLayout
>
> #log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n
>
> log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n
>
>
>
> ApplicationB log4j properties file
>
> # ***** Set root logger level to ERROR and its two appenders to stdout
> and R.
>
> log4j.rootLogger=debug, R
>
>
>
> # ***** stdout is set to be a ConsoleAppender.
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>
> # ***** stdout uses PatternLayout.
>
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>
> # ***** Pattern to output the caller's file name and line number.
>
> log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
>
>
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>
>
>
> # ***** R is set to be a RollingFileAppender.
>
> log4j.appender.R=org.apache.log4j.RollingFileAppender
>
> log4j.appender.R.File=c:/logs/APPB.log
>
> # ***** Max file size is set to 10000KB
>
> log4j.appender.R.MaxFileSize=10000KB
>
> # ***** Keep one backup file
>
> log4j.appender.R.MaxBackupIndex=1
>
> # ***** R uses PatternLayout.
>
> log4j.appender.R.layout=org.apache.log4j.PatternLayout
>
> log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p -
> %m%n
>
>
>
> # Set Struts/Commons log level
>
> log4j.logger.org.apache.struts=WARN
>
> log4j.logger.org.apache.commons=WARN
>
> Thanks and Regards
> Prashant Saraf
>
> ---------------------------------------------------------------------
> 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
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org

RE: Updating Wrong File

Posted by Prashant Saraf <ps...@cctc.com>.
I did that still not working...


Thanks and Regards
प्रशांत सराफ
(Prashant Saraf)
SE-I
Cross Country Infotech
Ext : 72543
-----Original Message-----
From: Eric.Wolf@bcbsks.com [mailto:Eric.Wolf@bcbsks.com] 
Sent: Tuesday, April 10, 2007 9:50 PM
To: Log4J Users List
Subject: Re: Updating Wrong File





Try putting the log4j JAR file in each of the application's WEB-INF/lib
directory so each application will have its own version to initialize.  I
ran into this when I tried to put the log4j JAR file in a shared library
and another application got "confused" on where to log.  I put it back in
my application and it has been fine.

Eric Wolf



                                                                           
             "Prashant Saraf"                                              
             <ps...@cctc.com>                                             
                                                                        To 
             04/10/2007 12:53          "Log4J Users List"                  
             AM                        <lo...@logging.apache.org>     
                                                                        cc 
                                                                           
             Please respond to                                       Topic 
               "Log4J Users                                                
                   List"                                           Subject 
             <log4j-user@loggi         Updating Wrong File                 
              ng.apache.org>                                               
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Hi all I am new to Log4j.

                  I had an issue. I am using Weblogic 8.1, I had two
application both had their log4j File. Now what is happing is
applicationA  is running properly with log4j. When I hit ApplicationB it
also works proper, Now when I hit applicationA it show me logged in
ApplicationB



ApplicationA log4j properties file



# Set root logger level to DEBUG and its only appender to A1.

log4j.rootLogger=WARN,A1, F1



log4j.category.org.apache.struts=WARN

log4j.category.org.apache.commons.logging=WARN

log4j.category. APPA =DEBUG

# A1 is set to be a ConsoleAppender.

log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

#log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n

log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
%m%n

# F1 is set to be a FileAppender.

log4j.appender.F1=org.apache.log4j.RollingFileAppender

log4j.appender.F1.file=c:/logs/APPA.log

log4j.appender.F1.MaxFileSize=10000KB

log4j.appender.F1.MaxBackupIndex=5

# F1 uses PatternLayout.

log4j.appender.F1.layout=org.apache.log4j.PatternLayout

#log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n

log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n



ApplicationB log4j properties file

# ***** Set root logger level to ERROR and its two appenders to stdout
and R.

log4j.rootLogger=debug, R



# ***** stdout is set to be a ConsoleAppender.

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

# ***** stdout uses PatternLayout.

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# ***** Pattern to output the caller's file name and line number.

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n



log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout



# ***** R is set to be a RollingFileAppender.

log4j.appender.R=org.apache.log4j.RollingFileAppender

log4j.appender.R.File=c:/logs/APPB.log

# ***** Max file size is set to 10000KB

log4j.appender.R.MaxFileSize=10000KB

# ***** Keep one backup file

log4j.appender.R.MaxBackupIndex=1

# ***** R uses PatternLayout.

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p -
%m%n



# Set Struts/Commons log level

log4j.logger.org.apache.struts=WARN

log4j.logger.org.apache.commons=WARN

Thanks and Regards
Prashant Saraf

---------------------------------------------------------------------
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

Re: Updating Wrong File

Posted by Er...@bcbsks.com.



Try putting the log4j JAR file in each of the application's WEB-INF/lib
directory so each application will have its own version to initialize.  I
ran into this when I tried to put the log4j JAR file in a shared library
and another application got "confused" on where to log.  I put it back in
my application and it has been fine.

Eric Wolf



                                                                           
             "Prashant Saraf"                                              
             <ps...@cctc.com>                                             
                                                                        To 
             04/10/2007 12:53          "Log4J Users List"                  
             AM                        <lo...@logging.apache.org>     
                                                                        cc 
                                                                           
             Please respond to                                       Topic 
               "Log4J Users                                                
                   List"                                           Subject 
             <log4j-user@loggi         Updating Wrong File                 
              ng.apache.org>                                               
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Hi all I am new to Log4j.

                  I had an issue. I am using Weblogic 8.1, I had two
application both had their log4j File. Now what is happing is
applicationA  is running properly with log4j. When I hit ApplicationB it
also works proper, Now when I hit applicationA it show me logged in
ApplicationB



ApplicationA log4j properties file



# Set root logger level to DEBUG and its only appender to A1.

log4j.rootLogger=WARN,A1, F1



log4j.category.org.apache.struts=WARN

log4j.category.org.apache.commons.logging=WARN

log4j.category. APPA =DEBUG

# A1 is set to be a ConsoleAppender.

log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

#log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n

log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
%m%n

# F1 is set to be a FileAppender.

log4j.appender.F1=org.apache.log4j.RollingFileAppender

log4j.appender.F1.file=c:/logs/APPA.log

log4j.appender.F1.MaxFileSize=10000KB

log4j.appender.F1.MaxBackupIndex=5

# F1 uses PatternLayout.

log4j.appender.F1.layout=org.apache.log4j.PatternLayout

#log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n

log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n



ApplicationB log4j properties file

# ***** Set root logger level to ERROR and its two appenders to stdout
and R.

log4j.rootLogger=debug, R



# ***** stdout is set to be a ConsoleAppender.

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

# ***** stdout uses PatternLayout.

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# ***** Pattern to output the caller's file name and line number.

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n



log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout



# ***** R is set to be a RollingFileAppender.

log4j.appender.R=org.apache.log4j.RollingFileAppender

log4j.appender.R.File=c:/logs/APPB.log

# ***** Max file size is set to 10000KB

log4j.appender.R.MaxFileSize=10000KB

# ***** Keep one backup file

log4j.appender.R.MaxBackupIndex=1

# ***** R uses PatternLayout.

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p -
%m%n



# Set Struts/Commons log level

log4j.logger.org.apache.struts=WARN

log4j.logger.org.apache.commons=WARN

Thanks and Regards
Prashant Saraf

---------------------------------------------------------------------
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


Updating Wrong File

Posted by Prashant Saraf <ps...@cctc.com>.
Hi all I am new to Log4j.

                  I had an issue. I am using Weblogic 8.1, I had two
application both had their log4j File. Now what is happing is
applicationA  is running properly with log4j. When I hit ApplicationB it
also works proper, Now when I hit applicationA it show me logged in
ApplicationB 

 

ApplicationA log4j properties file 

 

# Set root logger level to DEBUG and its only appender to A1.

log4j.rootLogger=WARN,A1, F1

 

log4j.category.org.apache.struts=WARN

log4j.category.org.apache.commons.logging=WARN

log4j.category. APPA =DEBUG

# A1 is set to be a ConsoleAppender.

log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

#log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n

log4j.appender.A1.layout.ConversionPattern= APPA >%5p [%d{HH:mm:ss}] -
%m%n

# F1 is set to be a FileAppender.

log4j.appender.F1=org.apache.log4j.RollingFileAppender

log4j.appender.F1.file=c:/logs/APPA.log

log4j.appender.F1.MaxFileSize=10000KB

log4j.appender.F1.MaxBackupIndex=5

# F1 uses PatternLayout.

log4j.appender.F1.layout=org.apache.log4j.PatternLayout

#log4j.appender.F1.layout.ConversionPattern=%5p [%t] - %m%n

log4j.appender.F1.layout.ConversionPattern=%5p [%d{HH:mm:ss}] - %m%n

 

ApplicationB log4j properties file 

# ***** Set root logger level to ERROR and its two appenders to stdout
and R.

log4j.rootLogger=debug, R

 

# ***** stdout is set to be a ConsoleAppender.

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

# ***** stdout uses PatternLayout.

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# ***** Pattern to output the caller's file name and line number.

log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

 

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

 

# ***** R is set to be a RollingFileAppender.

log4j.appender.R=org.apache.log4j.RollingFileAppender

log4j.appender.R.File=c:/logs/APPB.log

# ***** Max file size is set to 10000KB

log4j.appender.R.MaxFileSize=10000KB

# ***** Keep one backup file

log4j.appender.R.MaxBackupIndex=1

# ***** R uses PatternLayout.

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=[%d{MM-dd-yyyy HH:mm:ss}] %p -
%m%n

 

# Set Struts/Commons log level

log4j.logger.org.apache.struts=WARN

log4j.logger.org.apache.commons=WARN

Thanks and Regards
Prashant Saraf

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