Re: Problems with inheritance of com.foo... loggers

2010-02-04 Thread Douglas E Wegscheid
de.wota.segmentation.Bar will inherit from de.wota.segmentation, 
de.wota, and de but not de.wota.MyApp.

Change your configuration to set up logging for de.wota instead of 
de.wota.MyApp.

Douglas E Wegscheid
Lead Technical Analyst, Whirlpool Corporation
(269)-923-5278

A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation.



Jens Gruentjes jens.gruent...@ebira.de wrote on 02/04/2010 02:57:10 
AM:

 Hello to all readers,
 
 I am new to log4j and I encounter several problems which are maybe 
 caused by my limited understanding fo log4j.
 
 I have a simple setup with two classes (de.wota.MyApp and 
 de.wota.segmentation.Bar) and an xml configuration file for log4j. I 
 thought that the logger defined in Bar.java inherits its level and 
 most of all its appender(s) from the logger defined in MyApp.java. But 
 despite reading the manuals and the list archives I always get the 
 following error when I execute MyApp:
 
 j...@jensen ~/Java/wota_rw $ java de.wota.MyApp
 log4j: reset attribute= false.
 log4j: Threshold =null.
 log4j: Retreiving an instance of org.apache.log4j.Logger.
 log4j: Setting [de.wota.MyApp] additivity to [true].
 log4j: Level value for de.wota.MyApp is  [DEBUG].
 log4j: de.wota.MyApp level set to DEBUG
 log4j: Class name: [org.apache.log4j.ConsoleAppender]
 log4j: Setting property [target] to [System.out].
 log4j: Setting property [threshold] to [INFO].
 log4j: Parsing layout of class: org.apache.log4j.PatternLayout
 log4j: Setting property [conversionPattern] to [%8r %p %c %x - %m%n].
 log4j: Adding appender named [console] to category [de.wota.MyApp].
 0 INFO de.wota.MyApp  - Entering application.
 log4j:WARN No appenders could be found for logger 
(de.wota.segmentation.Bar).
 log4j:WARN Please initialize the log4j system properly.
 Parent is root
 1 INFO de.wota.MyApp  - Exiting application.
 j...@jensen ~/Java/wota_rw $
 
 What I expected to see was the output from Bar.java which is missing 
 here. I wanted to know who is the parent of the logger in Bar.java is 
 and it turned out to be root. I thought that this should be the logger 
 from MyApp.java. Can someone tell me what I misunderstand? I am a 
 little confused. The code follows below.
 
 Thanks for your explanations and your help!
 
 
 This is MyApp.java:
 
 package de.wota;
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.xml.DOMConfigurator;
 
 import de.wota.segmentation.Bar;
 
 public class MyApp {
  // Define a static logger variable so that it references the
  // Logger instance named MyApp.
  static Logger logger = Logger.getLogger(MyApp.class);
 
  public static void main(String[] args) {
 
  // Set up an xml configuration that logs on the console.
  DOMConfigurator.configureAndWatch(config_log.xml);
 
  logger.info(Entering application.);
  Bar bar = new Bar();
  bar.doIt();
  logger.info(Exiting application.);
  }
 }
 
 This is Bar.java:
 
 package de.wota.segmentation;
 
 import org.apache.log4j.Logger;
 
 public class Bar {
  static Logger logger = Logger.getLogger(Bar.class);
 
  public void doIt() {
logger.debug(Did it again!);
System.out.println(Parent is +logger.getParent().getName());
  }
 
 }
 
 And finally config_log.xml
 
 ?xml version=1.0 encoding=UTF-8 ?
 !DOCTYPE log4j:configuration SYSTEM log4j.dtd
 
 log4j:configuration debug=true 
 xmlns:log4j=http://jakarta.apache.org/log4j/;
 
appender name=console class=org.apache.log4j.ConsoleAppender
  param name=Target value=System.out/
  param name=threshold value=info /
  layout class=org.apache.log4j.PatternLayout
param name=ConversionPattern value=%8r %p %c %x - %m%n/
  /layout
/appender
 
logger name=de.wota.MyApp
  level value=DEBUG /
  appender-ref ref=console /
/logger
 
 /log4j:configuration
 
 -- 
 Kind regards
 Jens
 
 
 
 -
 To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
 For additional commands, e-mail: log4j-user-h...@logging.apache.org
 


Re: Problems with inheritance of com.foo... loggers

2010-02-04 Thread Jens Gruentjes

Hi Douglas,

thanks for your answer which helped me save a lot of time. Your  
explanation is evident but I did not realize that for myself.

--
Kind regards
Jens


Zitat von Douglas E Wegscheid douglas_e_wegsch...@whirlpool.com:


de.wota.segmentation.Bar will inherit from de.wota.segmentation,
de.wota, and de but not de.wota.MyApp.

Change your configuration to set up logging for de.wota instead of
de.wota.MyApp.

Douglas E Wegscheid
Lead Technical Analyst, Whirlpool Corporation
(269)-923-5278

A wrong note played hesitatingly is a wrong note. A wrong note played
with conviction is interpretation.



Jens Gruentjes jens.gruent...@ebira.de wrote on 02/04/2010 02:57:10
AM:


Hello to all readers,

I am new to log4j and I encounter several problems which are maybe
caused by my limited understanding fo log4j.

I have a simple setup with two classes (de.wota.MyApp and
de.wota.segmentation.Bar) and an xml configuration file for log4j. I
thought that the logger defined in Bar.java inherits its level and
most of all its appender(s) from the logger defined in MyApp.java. But
despite reading the manuals and the list archives I always get the
following error when I execute MyApp:

j...@jensen ~/Java/wota_rw $ java de.wota.MyApp
log4j: reset attribute= false.
log4j: Threshold =null.
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [de.wota.MyApp] additivity to [true].
log4j: Level value for de.wota.MyApp is  [DEBUG].
log4j: de.wota.MyApp level set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Setting property [target] to [System.out].
log4j: Setting property [threshold] to [INFO].
log4j: Parsing layout of class: org.apache.log4j.PatternLayout
log4j: Setting property [conversionPattern] to [%8r %p %c %x - %m%n].
log4j: Adding appender named [console] to category [de.wota.MyApp].
0 INFO de.wota.MyApp  - Entering application.
log4j:WARN No appenders could be found for logger

(de.wota.segmentation.Bar).

log4j:WARN Please initialize the log4j system properly.
Parent is root
1 INFO de.wota.MyApp  - Exiting application.
j...@jensen ~/Java/wota_rw $

What I expected to see was the output from Bar.java which is missing
here. I wanted to know who is the parent of the logger in Bar.java is
and it turned out to be root. I thought that this should be the logger
from MyApp.java. Can someone tell me what I misunderstand? I am a
little confused. The code follows below.

Thanks for your explanations and your help!


This is MyApp.java:

package de.wota;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import de.wota.segmentation.Bar;

public class MyApp {
 // Define a static logger variable so that it references the
 // Logger instance named MyApp.
 static Logger logger = Logger.getLogger(MyApp.class);

 public static void main(String[] args) {

 // Set up an xml configuration that logs on the console.
 DOMConfigurator.configureAndWatch(config_log.xml);

 logger.info(Entering application.);
 Bar bar = new Bar();
 bar.doIt();
 logger.info(Exiting application.);
 }
}

This is Bar.java:

package de.wota.segmentation;

import org.apache.log4j.Logger;

public class Bar {
 static Logger logger = Logger.getLogger(Bar.class);

 public void doIt() {
   logger.debug(Did it again!);
   System.out.println(Parent is +logger.getParent().getName());
 }

}

And finally config_log.xml

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

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

   appender name=console class=org.apache.log4j.ConsoleAppender
 param name=Target value=System.out/
 param name=threshold value=info /
 layout class=org.apache.log4j.PatternLayout
   param name=ConversionPattern value=%8r %p %c %x - %m%n/
 /layout
   /appender

   logger name=de.wota.MyApp
 level value=DEBUG /
 appender-ref ref=console /
   /logger

/log4j:configuration

--
Kind regards
Jens



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






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



AW: Problems with inheritance of com.foo... loggers

2010-02-04 Thread Bender Heri
There is one point more: You do not define a root logger in your config which 
has some benefits
The root is the parent for all loggers which are not explicitely defined (e.g. 
also for third party libraries like org.apache).
Typically you set the root logger level to WARN. And for the package/classes 
which you want to examine deeper you define a extra logger with desired lower 
level.
If you want to have a lot of logger configurations which differ only in level 
setting but have all the same appender, then you define the appender only once 
in the root logger. 
Only if you explicitely want to have one distinct logger to log to another 
appender you define it in the respective logger definition and set the 
attribute additivity=false (default is true).
Heri 

-Ursprüngliche Nachricht-
Von: Jens Gruentjes [mailto:jens.gruent...@ebira.de] 
Gesendet: Donnerstag, 4. Februar 2010 15:36
An: log4j-user@logging.apache.org
Betreff: Re: Problems with inheritance of com.foo... loggers

Hi Douglas,

thanks for your answer which helped me save a lot of time. Your explanation is 
evident but I did not realize that for myself.
--
Kind regards
Jens


Zitat von Douglas E Wegscheid douglas_e_wegsch...@whirlpool.com:

 de.wota.segmentation.Bar will inherit from de.wota.segmentation, 
 de.wota, and de but not de.wota.MyApp.

 Change your configuration to set up logging for de.wota instead of 
 de.wota.MyApp.

 Douglas E Wegscheid
 Lead Technical Analyst, Whirlpool Corporation
 (269)-923-5278

 A wrong note played hesitatingly is a wrong note. A wrong note played 
 with conviction is interpretation.



 Jens Gruentjes jens.gruent...@ebira.de wrote on 02/04/2010 
 02:57:10
 AM:

 Hello to all readers,

 I am new to log4j and I encounter several problems which are maybe 
 caused by my limited understanding fo log4j.

 I have a simple setup with two classes (de.wota.MyApp and
 de.wota.segmentation.Bar) and an xml configuration file for log4j. I 
 thought that the logger defined in Bar.java inherits its level and 
 most of all its appender(s) from the logger defined in MyApp.java. 
 But despite reading the manuals and the list archives I always get 
 the following error when I execute MyApp:

 j...@jensen ~/Java/wota_rw $ java de.wota.MyApp
 log4j: reset attribute= false.
 log4j: Threshold =null.
 log4j: Retreiving an instance of org.apache.log4j.Logger.
 log4j: Setting [de.wota.MyApp] additivity to [true].
 log4j: Level value for de.wota.MyApp is  [DEBUG].
 log4j: de.wota.MyApp level set to DEBUG
 log4j: Class name: [org.apache.log4j.ConsoleAppender]
 log4j: Setting property [target] to [System.out].
 log4j: Setting property [threshold] to [INFO].
 log4j: Parsing layout of class: org.apache.log4j.PatternLayout
 log4j: Setting property [conversionPattern] to [%8r %p %c %x - %m%n].
 log4j: Adding appender named [console] to category [de.wota.MyApp].
 0 INFO de.wota.MyApp  - Entering application.
 log4j:WARN No appenders could be found for logger
 (de.wota.segmentation.Bar).
 log4j:WARN Please initialize the log4j system properly.
 Parent is root
 1 INFO de.wota.MyApp  - Exiting application.
 j...@jensen ~/Java/wota_rw $

 What I expected to see was the output from Bar.java which is missing 
 here. I wanted to know who is the parent of the logger in Bar.java is 
 and it turned out to be root. I thought that this should be the 
 logger from MyApp.java. Can someone tell me what I misunderstand? I 
 am a little confused. The code follows below.

 Thanks for your explanations and your help!


 This is MyApp.java:

 package de.wota;

 import org.apache.log4j.Logger;
 import org.apache.log4j.xml.DOMConfigurator;

 import de.wota.segmentation.Bar;

 public class MyApp {
  // Define a static logger variable so that it references the
  // Logger instance named MyApp.
  static Logger logger = Logger.getLogger(MyApp.class);

  public static void main(String[] args) {

  // Set up an xml configuration that logs on the console.
  DOMConfigurator.configureAndWatch(config_log.xml);

  logger.info(Entering application.);
  Bar bar = new Bar();
  bar.doIt();
  logger.info(Exiting application.);
  }
 }

 This is Bar.java:

 package de.wota.segmentation;

 import org.apache.log4j.Logger;

 public class Bar {
  static Logger logger = Logger.getLogger(Bar.class);

  public void doIt() {
logger.debug(Did it again!);
System.out.println(Parent is +logger.getParent().getName());
  }

 }

 And finally config_log.xml

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

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

appender name=console class=org.apache.log4j.ConsoleAppender
  param name=Target value=System.out/
  param name=threshold value=info /
  layout class=org.apache.log4j.PatternLayout
param name=ConversionPattern value=%8r %p %c %x - %m%n/
 

Possible to get unambiguous timestamp with v1.2.15 ?

2010-02-04 Thread David Balažic
Hi!

I am using log4j 1.2.15 and noticed that the timestamps in logs have
no TZ information.
They are created by config like this:

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d DATABASE-%-5p [%c] - %m%n

Is there a way to get either:
 - same format, but with TZ info (offset), or
 - same format, but time in UTC
without switching to other or additional software?

I think I can get the first by using a pattern like %d{-MM-dd
HH:mm:ss,SSS Z}
that is using the Z pattern letter. That would then use
java.text.SimpleDateFormat to
do the formatting, right?
The javadocs are a bit vague:

The date format specifier admits the same syntax as the time pattern
string of the SimpleDateFormat.

(source: 
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html)


It says the same syntax is used, but it is unclear it actually
SimpleDateFormat is used or a different, compatible implementation.

If it is SimpleDateFormat used, how bad is the performance hit that is
mentioned there?


For the second option, I could set the system time zone to UTC, or
maybe the applications* zone?

Any comments? Better ideas?

* - it is actually an application server, tomcat, JBoss or similar,
not set in stone yet


I also see in the API doc, that ISO8601DateFormat has a constructor
that takes a TimeZone argument.
Can that be used? Ideally just by changing the config file?

Regards,
David

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



Re: Possible to get unambiguous timestamp with v1.2.15 ?

2010-02-04 Thread Curt Arnold
Check out the EnhancedPatternLayout in the log4j extras companion, 
http://logging.apache.org/log4j/companions/extras/.  It is an enhanced version 
of PatternLayout that is usage-compatible.  Basically, add log4j-extras.jar to 
your path, change the Layout class to EnhancedPatternLayout and use a pattern 
like %d{HH:mm:ss}{GMT} or whatever any other recognized timezone in the second 
set of braces.

Performance of SimpleDateFormat is a significant issue.  PatternLayout has an 
independent implementation, EnhancedPatternLayout wraps a cache around 
SimpleDateFormat to avoid calling it repeatedly for timestamps within an 
interval.

http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/EnhancedPatternLayout.html


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