• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

log4j w/apache

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
How can I stop the Apache debug log4j log statements but still use framework?
I am not clear if I put in log4j.rootlogger=OFF do I have to put in the properties file a
log4j.logger.[com.xyz.aaa]=DEBUG,A1
og4j.logger.[com.xyz.bbb]=DEBUG,A1
and then from within the each object I want to log do I do:
Logger aaa = Logger.getLogger(aaa.class)
and then just use api from there? That would be elegant, if not in understanding, grin.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I"m not sure what you're asking.
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:I"m not sure what you're asking.



Hi
I appear to groping my way through.
I cant use the std configuration of l4j, b/c all of the debug code for apache ...digester & digester.sax shows. I thought I could disable it with log4j.rootlogger=OFF and configure my own withing the individual object, loosing elegant runtime configuration, but at least it would work.

I am still seeing the org.apache.commons.digester.Digester, and all the parsing of the struts configuration files. However my technique did work and I am getting log lines from my individually configured objects.

My questions are two
1. How can I stop debug from Apache without setting a higher leve on the root logger? I want to use debug level in my code.
2. Is there a configuration which which I can have runtime configuration of my object specific loggers? What is the syntax to configure them from the log4j.properties file specific for each object's class name AND how do I access them from within the specific object class?


Figures:
Fig1
This is the configuration is /src
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# 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=%-4r [%t] %-5p %c %x - %m%n

Fig2
This is how I am creating the child Loggers per desired object
static Logger ver02_lfj=Logger.getLogger(obj_ver02.class.getName());

java.util.Properties props = new java.util.Properties();
try {
props.load(getClass().getResourceAsStream("/log4j.properties"));
}
catch (IOException ex) {
}
PropertyConfigurator.configure(props);
ver02_lfj.setLevel(Level.DEBUG);
ver02_lfj.debug("My FIRST Log4J. obj_ver02");
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set the rootlogger to DEBUG sure, you're going to get mass quantities of debug log messages.

You can turn specific packages on/off by configuring individual loggers for them.

Personally I usually just set the root logger to INFO or WARN and set *my* packages to DEBUG. I don't find anything particularly elegant about runtime configuration, and it's a rare occasion I ever do anything more interesting with my Log instances than just create class-specific loggers.
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave
Thanks. But I thought I set the root to OFF, if that is even a command, that I "picked" up ad hoc on some google search.

The reason I find runtime configuration elegant is I have many objects, and now as I understand it I am configuring them in the constructor of each object, and setting their logging level. This means, as I understand it, that if I want to simulate production I have to go to each object and set its level to something high. This requires a source edit and recompile. I would like to just do it from the configuration file. And this is b/c the apache code has taken over the DEBUG level with its line. Yes, I am sure I could recompile it, but I prefer to buy my groceries and pasta vbg.

If that is possible, what is the syntax to create those object specific debuggers in the log4j.properties AND what is the calling syntax in the object specific code to set the logging information?
 
Marshal
Posts: 67286
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand correctly, you are setting the levels programmatically within the code?

Then of course you need to change it every time you wan tto change the logging behavior. Why are you doing that? The whole point of Log4J is to set up the logging and then be able to control it completely from configuration without the need for code changes.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I'm not quite sure I understand the issue.

In general you'll see configuration like this:This means that everything not explicitly defined has a log level of WARN: the app will be relatively quiet. However I've explicitly configured several high-level packages: I'll get lots of log messages from things in the com.davenewton.foo and org.apache.struts2 packages, almost nothing from ognl, and INFO msgs from com.opensymphony.xwork2.

In the Java code itself logs are defined like this:To make that log message not appear I simply change the com.davenewton.foo package's log level to, for example, INFO--in the log4j.properties file.

Maybe if you showed some of your code and/or explained what you're trying to do we'd understand the problem more clearly.
 
What a show! What atmosphere! What fun! What a tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!