Nancy,

The method you have outlined below is simpler and should work just fine.
Yes, it is possible to attach a specific appender to a specific logger.  You
probably don't want the reference to the socket hub appender in the root
logger:

<logger name="placeOrder">
  <appender-ref ref="SOCKET_HUB"/>
</logger>

<root>...</root>

This will ensure that the placeOrder messages will only go to SOCKET_HUB
once (the messages will still appear in all appenders attached to root).

The limitation is that you have to have a specific logger for all "place
order" activity and so code will need to get that logger (or call your
placeOrderLog method).  Or, it could be strength, depending on how you look
at it.  Overall, not a bad solution.

The one I was proposing, using filters, is a bit more complex but is more
flexible in the client code.  For example, once the user enters a portion of
the code where an order is being placed, you could set that state in the NDC
or MDC.  The filter configuration on the SocketHubAppender would find this
info in the NDC and MDC and then allow those log messages through.  No
specific knowledge of a specific "place order" logger would be needed.

I'll post the filters to the list on Monday, and you can judge for yourself.
As I said, your current solution is workable and efficient.

-Mark

> -----Original Message-----
> From: Nancy [mailto:[EMAIL PROTECTED]]
> Sent: Friday, February 07, 2003 11:31 AM
> To: Log4J Users List
> Subject: Re: questions related to config xml file
> 
> 
> Mark:
> 
> Thank you very much for your help and your invitation. I am 
> very glad to
> accept the invitation and give them a try. It sounds pretty 
> interesting to
> me. Please send me the jar file whenever you are convenient.
> 
> Mark, since right now I am trying to restrict the set of 
> logging events by
> using util class combined with configuration file, which is totally
> different with what you suggestted. I am not sure if I am 
> right, or it is
> not possible to do so. I would like to describe what I have done and
> appreciate your idea.
> 
> The utility class for initializing the major activities' log. 
> The following
> is the snippet of the util class:
> ===================================================================
> /** Class <code>Log</code> common log class for other major 
> activities log
> class to extends from*/
> public final class ActivitiesLog {
> 
> //var declaration
>    private static ActivitiesLog activityLog = null;
>    private Logger placeOrderLog = null;
> 
> ...................
>  private static ActivitiesLog getInstance() {
>       if (activityLog == null) activityLog  = new ActivitiesLog();
>       return activityLog ;
>    }
> 
>    private ActivitiesLog() {
> 
> DOMConfigurator.configure(Settings.getInstance().getSetting("/
> /Configuration
> file"));
>       placeOrderLog = Logger.getLogger("placeOrder");
>    }
> 
>    public static void placeOrderLog(String s) {
>       getInstance().placeOrderLog .info(s); //begin to log
>    }
> }
> 
> 
> When placeOrder(for example) happenes, I call placeOrderLog(String s)
> method( as showed above) to initialize log for "placeOrder" 
> activity. In the
> configuration file, there are the following lines:
> 
>     <appender name="SOCKET_HUB"
> class="org.apache.log4j.net.SocketHubAppender">
>        <param name="Port" value="7001"/>
>     </appender>
> 
>     <logger name="placeOrder" >
>          <appender-ref ref="SOCKET_HUB"/>
>     </logger>
> 
>     <root>....<appender-ref ref="SOCKET_HUB" /></root>
> 
> ==============================================================
> ==============
> =======================
> In a word, is it possible to configurate a specific logger 
> and attach it to
> a specific appender in the XML style configuration file?
> 
> Thank you very much for your time. I really appreciate your help.
> 
> Regards.
> Nancy
> 
> 
> 
> 
> ----- Original Message -----
> From: "Mark Womack" <[EMAIL PROTECTED]>
> To: "'Log4J Users List'" <[EMAIL PROTECTED]>
> Sent: Friday, February 07, 2003 1:45 PM
> Subject: RE: questions related to config xml file
> 
> 
> > Nancy, thanks for the details.  I believe I understand what 
> you are trying
> > to do.
> >
> > Yes, it is possible to restrict the set of logging events 
> sent to the
> remote
> > client by the SocketHubAppender.  And I think this is a 
> very good use of
> > SocketHubAppender, btw, given your requirements.
> >
> > The best method for restricting events that are sent via 
> SocketHubAppender
> > (or SocketAppender for that matter) is configuring a filter 
> chain on that
> > appender.  You can see the javadoc information on log4j filters at:
> >
> > 
> http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/spi/
> Filter.html
> >
> > And there are few good examples in the varia package:
> >
> >
> http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/vari
> a/package-fram
> > e.html
> >
> > But, I have been working on a new package of useful filters 
> for the v1.3
> > release.  They are fully compatible with v1.2.X.  If I 
> package them up
> into
> > a jar file, would you be interested in giving them a try?  
> They allow full
> > configuration of a filter chain using almost any set of 
> source criteria
> you
> > might want (contents of the message string, contents of the 
> MDC, contents
> of
> > the NDC, level of the logger, etc).
> >
> > And this invitation is for anyone out there that might be 
> interested.
> >
> > -Mark
> >
> > > -----Original Message-----
> > > From: Nancy [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, December 11, 2002 11:14 AM
> > > To: Log4J Users List
> > > Subject: Re: questions related to config xml file
> > >
> > >
> > > Hi,Mark:
> > >
> > > Thank you so much for your reply.
> > >
> > > Sorry for not providing enough information.
> > >
> > > The following is the description of what I am attemping 
> to accomplish:
> > > We have developed a web application. Now I am developing a
> > > swing application
> > > which is used to monitor some major activities (such as place
> > > orders, login,
> > > logout and etc.) happened in the web application. The
> > > connection between the
> > > swing application and the web application is initialized 
> by the swing
> > > application(I mean when a system admin clicks the connect
> > > button on the
> > > swing user interface). After the connection is established,
> > > whenever users
> > > login, logout, or place orders in the web application, the
> > > swing application
> > > should IMMEDIATELY detects them, and display the appropriate
> > > message(Such as
> > > "user has place an order", "user has login the web site").
> > > After doing some
> > > study on log4j api, we decided to use SocketHubAppender in the web
> > > application to accomplish the senario.
> > >
> > >
> > > I am using xml formate to config the configuration file. The
> > > following is
> > > what I configured in the configuration file: (I omitted the
> > > parts that are
> > > not related to the senario):
> > > ...
> > > <log4j:configuration 
> xmlns:log4j='http://jakarta.apache.org/log4j/'>
> > >    .......
> > >   <!-- for Activity monitor purpose.-->
> > >     <!-- SocketHubAppender does not use a layout-->
> > >
> > >     <appender name="SOCKET_HUB"
> > > class="org.apache.log4j.net.SocketHubAppender">
> > >        <param name="Port" value="7001"/>
> > >     </appender>
> > >
> > >     <root>
> > > ....
> > >     <!-- for Activity monitor purpose. -->
> > >       <appender-ref ref="SOCKET_HUB" />
> > >     </root>
> > >
> > > </log4j:configuration>
> > >
> > >
> > > Question1:                   What else do I need to config in the
> > > configuration file?
> > > Question2:                    I ONLY want SOME activities to use
> > > SocketHubAppender,  for instance, activities such as login,
> > > logout, place
> > > orders. How should I do to limit the use of SocketHubAppender
> > > only to those
> > > activities? We have already used logging mechnism for ALL
> > > activities for
> > > general logging purpose(such as logging to file systems,
> > > console), and we
> > > prefer those general logging still exist while add the use
> > > SocketHubAppender
> > > for some activities.
> > >
> > > I tried my best to make the senario and the questions clear.
> > > However,  I am
> > > very glad to explain them in more detail  if you have any confuse.
> > >
> > > Thank you very much for your reply.
> > >
> > > Best regards,
> > >
> > > Nancy
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Mark Womack" <[EMAIL PROTECTED]>
> > > To: "'Log4J Users List'" <[EMAIL PROTECTED]>
> > > Sent: Thursday, February 06, 2003 12:52 PM
> > > Subject: RE: questions related to config xml file
> > >
> > >
> > > > Nancy,
> > > >
> > > > Can you give more detail of what you are trying to 
> accomplish.  The
> > > > SocketHubAppender does not accept any configuration for the
> > > XMLAppender.
> > > It
> > > > is just a mechanism to stuff the logging event over a
> > > socket to a remote
> > > > client.  The remote client would be responsible for 
> setting up an
> > > > XMLAppender for output.
> > > >
> > > > -Mark
> > > >
> > > > > -----Original Message-----
> > > > > From: Nancy [mailto:[EMAIL PROTECTED]]
> > > > > Sent: Tuesday, December 10, 2002 11:54 AM
> > > > > To: Log4J Users List
> > > > > Subject: questions related to config xml file
> > > > >
> > > > >
> > > > > Hi:
> > > > >
> > > > > I am implementing remote debugging using SocketHubAppender. I
> > > > > want to use
> > > > > XML to write the configuration file. I read log4j.dtd,
> > > but not fully
> > > > > understand it. I guess because I am doing remote debugging,
> > > > > so I need to
> > > > > config log4j:eventSet, and inside the element, there 
> can be 0-many
> > > > > log4j:event elements.I tried to find an example on how to
> > > > > config this, but
> > > > > unfortunatly, I didn't find. Could you help me on how to
> > > config the
> > > > > configuration file, or point me to a link where there is an
> > > > > example. Thank
> > > > > you very much for your help.
> > > > >
> > > > > regards,
> > > > >
> > > > > Nancy
> > > > >
> > > > >
> > > > >
> > > 
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: 
> [EMAIL PROTECTED]
> > > > > For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > > > >
> > > >
> > > >
> > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: 
> [EMAIL PROTECTED]
> > > > For additional commands, e-mail: 
> [EMAIL PROTECTED]
> > > >
> > >
> > >
> > > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: 
> [EMAIL PROTECTED]
> > >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

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

Reply via email to