The reason to do this is exactly what you state. Control over how logging gets done simply by changing the config. Using the 1.2 classes/syntax, an example would be:
Say you have the following two classes: com.foo.bar.MyMain com.foo.bar.MyHelper each which define a logger based on its class name. Then the following line in the config file: log4j.logger.com.foo.bar=DEBUG, FILE1 states that all messages to a category starting with "com.foo.bar" (this also would include "com.foo.bar.util" and com.foo.bar.util.jdo" etc) should be sent to the defined appender named FILE1 Say later you decide that you want logging from MyHelper to go to a seperate log file. Then just do this in the config: log4j.logger.com.foo.bar=DEBUG, FILE1 log4j.logger.com.foo.bar.MyHelper=WARN, FILE2 # This next line says to not also send it to FILE1 log4j.additivity.com.foo.bar.MyHelper=false Now everything logs as before, except that output from MyHelper will show up in the target of the FILE2 appender. To answer your specific questions: >>1. Does it mean that I can control logging at class level. It means you can control logging at any level you want. The project I work on, we decided to functionally group the loggers. For example, we use named loggers such as "system.managers.models" and "system.managers.cache" etc. Each class then obtains a Logger based on its functional role: Logger log = Logger.getLogger( "system.managers.models" ). One of the many cool things about log4j is that is extremely flexible. >>2. Thinking from a project level how can i say that all classes in a particular >>package should log into appender A. An example was shown above. Note however that "sub-packages" will also be included unless you explicitly set up config entries for them also and turn their additivity flag to false. >>3. Let us say 2 classes are logging into the same file at the same time does >>log4j guarentee that they will be entered into the file. Now idea what your asking. If your mean will log statements from both classes show up in the same file, then the answer is: of course they will. >>4. In essence I understood the logging at a class level not at a project level. Again, not sure I understand the question... ----- Original Message ----- From: "Modha Kumar" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, February 15, 2002 7:59 PM Subject: Category : Why so many of them Hi All I have this question on Categories concept of log4j In the documentation it says you can have multiple categories for the logger. And in each class in my project I specify static Category cat =Category.getInstance(MyClass.class.getName()); so this as i understand will create a category per class. So if I have 50 classes in my project it will create 50 categories. Now why will I use so many categories. 1. Does it mean that I can control logging at class level. 2. Thinking from a project level how can i say that all classes in a particular package should log into appender A. 3. Let us say 2 classes are logging into the same file at the same time does log4j guarentee that they will be entered into the file. 4. In essence I understood the logging at a class level not at a project level. Can anybody clarify these. Thanks for suggesting vipan website it was helpful. Modha/- -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>