Re: Log based on object and not the class

2003-12-11 Thread steve . beech

Scott,

Why not add a switch parameter to the parent method?

i.e

Class Parent {
 ...
 Public void myMethod(boolean b) {
 if (b==true) {
  Logger.debug(logging message);
 }
 }
}

Class Child1 extends Parent {
 ...
 Public void execute1() {
 this.myMethod(true);
 }
}

Class Child2 extends Parent {
 ...
 Public void execute2() {
 this.myMethod(false);
 }
}

Steve




   

  Scott Melcher  

  [EMAIL PROTECTED]To:   'Log4J Users List' [EMAIL 
PROTECTED]  
  orp.com cc: 

   Subject:  Log based on object and not 
the class 
  11/12/2003 15:46 

  Please respond to

  Log4J Users 

  List

   

   





Hi, my problem is that in my object architecture/hierarchy I have dozens of
classes that extend a single parent class.  The parent class has a method
that is called by all of the child classes.  It is in this method that I
have several log statements.  The problem is that I only have the ability
to
turn the logger on or off for that parent class.  If I turn it on then I
will get too many logging messages.  I would only like to log messages in
that parent class for a given child class.
I know I am not explaing this well so I will add a quick code example.

In my example I only want to log messages from the Child1 class.  Therefore
if I was to execute my two child classes I would want to get a single
logging message.

Class Parent {
 ...
 Public void myMethod() {
 Logger.debug(logging message);
 }
}

Class Child1 extends Parent {
 ...
 Public void execute1() {
 this.myMethod();
 }
}

Class Child2 extends Parent {
 ...
 Public void execute2() {
 this.myMethod();
 }
}

THANKS for any input you can give!



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



RE: Log based on object and not the class

2003-12-11 Thread Adrian Janssen
Pass the child object's Logger in to the parent method.

-Original Message-
From: Scott Melcher [mailto:[EMAIL PROTECTED]
Sent: 11 December 2003 15:47
To: 'Log4J Users List'
Subject: Log based on object and not the class


Hi, my problem is that in my object architecture/hierarchy I have dozens of
classes that extend a single parent class.  The parent class has a method
that is called by all of the child classes.  It is in this method that I
have several log statements.  The problem is that I only have the ability to
turn the logger on or off for that parent class.  If I turn it on then I
will get too many logging messages.  I would only like to log messages in
that parent class for a given child class.
I know I am not explaing this well so I will add a quick code example.

In my example I only want to log messages from the Child1 class.  Therefore
if I was to execute my two child classes I would want to get a single
logging message.

Class Parent {
...
Public void myMethod() {
Logger.debug(logging message);
}
}

Class Child1 extends Parent {
...
Public void execute1() {
this.myMethod();
}
}

Class Child2 extends Parent {
...
Public void execute2() {
this.myMethod();
}
}

THANKS for any input you can give!



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



RE: Log based on object and not the class

2003-12-11 Thread Scott Melcher
I considered doing something like you suggested but I just hate to add code
in order to handle logging.  Our application is very large and I would have
to add some object layers in order to get it to work.  It seems like
overkill.  For now I may just put external filters on my application that
simply display the messages I am interested in.

Thanks for the response.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 11, 2003 8:47 AM
To: Log4J Users List
Subject: Re: Log based on object and not the class


Scott,

Why not add a switch parameter to the parent method?

i.e

Class Parent {
 ...
 Public void myMethod(boolean b) {
 if (b==true) {
  Logger.debug(logging message);
 }
 }
}

Class Child1 extends Parent {
 ...
 Public void execute1() {
 this.myMethod(true);
 }
}

Class Child2 extends Parent {
 ...
 Public void execute2() {
 this.myMethod(false);
 }
}

Steve




 

  Scott Melcher

  [EMAIL PROTECTED]To:   'Log4J Users
List' [EMAIL PROTECTED]  
  orp.com cc:

   Subject:  Log based on object
and not the class 
  11/12/2003 15:46

  Please respond to

  Log4J Users

  List

 

 





Hi, my problem is that in my object architecture/hierarchy I have dozens of
classes that extend a single parent class.  The parent class has a method
that is called by all of the child classes.  It is in this method that I
have several log statements.  The problem is that I only have the ability
to
turn the logger on or off for that parent class.  If I turn it on then I
will get too many logging messages.  I would only like to log messages in
that parent class for a given child class.
I know I am not explaing this well so I will add a quick code example.

In my example I only want to log messages from the Child1 class.  Therefore
if I was to execute my two child classes I would want to get a single
logging message.

Class Parent {
 ...
 Public void myMethod() {
 Logger.debug(logging message);
 }
}

Class Child1 extends Parent {
 ...
 Public void execute1() {
 this.myMethod();
 }
}

Class Child2 extends Parent {
 ...
 Public void execute2() {
 this.myMethod();
 }
}

THANKS for any input you can give!



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



RE: Log based on object and not the class - Solution

2003-12-11 Thread Scott Melcher
Ceki,

That’s an excellent solution.  It's not very intrusive to the application.
I pay the expense of an extra method call but the benefits probably outweigh
the cost.

Thank you very much.

-Original Message-
From: Ceki Gülcü [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 11, 2003 9:27 AM
To: Log4J Users List
Subject: RE: Log based on object and not the class

Scott,

I just committed a possible solution to the problem you raised.
You can look at it here:
http://cvs.apache.org/viewcvs.cgi/jakarta-log4j/examples/objectBased/

Does it solve the problem?

At 08:56 AM 12/11/2003 -0700, you wrote:
I considered doing something like you suggested but I just hate to add code
in order to handle logging.  Our application is very large and I would have
to add some object layers in order to get it to work.  It seems like
overkill.  For now I may just put external filters on my application that
simply display the messages I am interested in.

Thanks for the response.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 11, 2003 8:47 AM
To: Log4J Users List
Subject: Re: Log based on object and not the class


Scott,

Why not add a switch parameter to the parent method?

i.e

Class Parent {
  ...
  Public void myMethod(boolean b) {
  if (b==true) {
   Logger.debug(logging message);
  }
  }
}

Class Child1 extends Parent {
  ...
  Public void execute1() {
  this.myMethod(true);
  }
}

Class Child2 extends Parent {
  ...
  Public void execute2() {
  this.myMethod(false);
  }
}

Steve

-- 
Ceki Gülcü

  For log4j documentation consider The complete log4j manual
  ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp  



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



RE: Log based on object and not the class

2003-12-11 Thread Andy McBride
I use something like this:

public class Parent
{
  protected Logger log = Logger.getLogger(getClass());
  
  public void myMethod()
  {
log.debug(logging message);
  }
}

public class Child1 extends Parent
{
  public void execute1()
  {
myMethod();
  }
}

public class Child2 extends Parent
{
  public void execute2()
  {
myMethod();
  }
}

public class TestChildren
{
  public static void main(String[] args)
  {
new Child1().execute1();
new Child2().execute2();
  }
}

I the control the logging with the log4j.xml:

?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE log4j:configuration SYSTEM log4j.dtd

log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/;
debug=false

  !--=  Appender definitions
==--

  appender name=CONSOLE class=org.apache.log4j.ConsoleAppender
param name=Threshold value=debug/
layout class=org.apache.log4j.PatternLayout
  param name=ConversionPattern value=%-5p: %c{1}.%M: %m%n/
/layout
  /appender

  !--=  Logger definitions
==--

  logger name=Child1
level value=debug/
  /logger
  
  logger name=Child2
level value=off/
  /logger

  !--=  Root Logger  ==--

  root
level value=all/
appender-ref ref=CONSOLE/
  /root

/log4j:configuration

Regards

Andy


 -Original Message-
 From: Scott Melcher [mailto:[EMAIL PROTECTED] 
 Sent: 11 December 2003 15:47
 To: 'Log4J Users List'
 Subject: Log based on object and not the class
 
 
 Hi, my problem is that in my object architecture/hierarchy I 
 have dozens of classes that extend a single parent class.  
 The parent class has a method that is called by all of the 
 child classes.  It is in this method that I have several log 
 statements.  The problem is that I only have the ability to 
 turn the logger on or off for that parent class.  If I turn 
 it on then I will get too many logging messages.  I would 
 only like to log messages in that parent class for a given 
 child class. I know I am not explaing this well so I will add 
 a quick code example.
 
 In my example I only want to log messages from the Child1 
 class.  Therefore if I was to execute my two child classes I 
 would want to get a single logging message.
 
 Class Parent {
   ...
   Public void myMethod() {
   Logger.debug(logging message);
   }
 }
 
 Class Child1 extends Parent {
   ...
   Public void execute1() {
   this.myMethod();
   }
 }
 
 Class Child2 extends Parent {
   ...
   Public void execute2() {
   this.myMethod();
   }
 }
 
 THANKS for any input you can give!
 
 
 
 -
 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]



RE: Log based on object and not the class

2003-12-11 Thread Jensen, Jeff
I have a couple of thoughts for you, but both violate at least one restriction you 
placed on the solution!  The ideas may lead you to something better than you currently 
have though.

1)  Use Template Method pattern.

You mentioned not wanting to change code, and this solution does require that.  Yet I 
suggest it as an alternative (an inverse) to the other suggestion to pass in the 
child's logger to the parent method.  This approach enables gradual implementation as 
the parent's methods signatures do not change (which obviously would cause an 
immediate change to all callers of a method).

For example, in the parent class, create a method:
  protected Logger getChildLogger()
  {
return LOG;
  }

By default, it returns its own logger.  Have the subclasses override that method to 
return their own logger.

Then, in the parent class' methods you want to log to the child's logger, call that 
method to get it first.  Until a subclass overrides that method, there is no change 
from current behavior.

When you get to the point of having all subclasses override the getChildLogger() 
method, then make the one in the parent class abstract to guarantee each subclass 
having an implementation.


2)  Use a TRACE like behavior.  At the beginning of each method, log this:
  LOG.debug(methodName: begin)

and at the end of each method, log this:
  LOG.debug(methodName: end)

Then you will know that all log calls in between those two messages for a given user 
[solve with NDCing the user name] were as a result of executing that method.  This of 
course requires the parent class' messages turned on, which also violates something 
you said you did not want - too many from it!


 -Original Message-
 From: Scott Melcher [mailto:[EMAIL PROTECTED]
 Sent: Thursday, December 11, 2003 9:47 AM
 To: 'Log4J Users List'
 Subject: Log based on object and not the class
 
 
 Hi, my problem is that in my object architecture/hierarchy I 
 have dozens of
 classes that extend a single parent class.  The parent class 
 has a method
 that is called by all of the child classes.  It is in this 
 method that I
 have several log statements.  The problem is that I only have 
 the ability to
 turn the logger on or off for that parent class.  If I turn 
 it on then I
 will get too many logging messages.  I would only like to log 
 messages in
 that parent class for a given child class.
 I know I am not explaing this well so I will add a quick code example.
 
 In my example I only want to log messages from the Child1 
 class.  Therefore
 if I was to execute my two child classes I would want to get a single
 logging message.
 
 Class Parent {
   ...
   Public void myMethod() {
   Logger.debug(logging message);
   }
 }
 
 Class Child1 extends Parent {
   ...
   Public void execute1() {
   this.myMethod();
   }
 }
 
 Class Child2 extends Parent {
   ...
   Public void execute2() {
   this.myMethod();
   }
 }
 
 THANKS for any input you can give!
 
 
 
 -
 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]