
Hi All, I was wondering if there is an easy way to test the validity of an XML configuration file. Just as an example I have this now in the config file <blah blah blah> JoranConfigurator doConfigure accepts it and no exception is thrown. Nothing gets printed or written to a file etc. however I'd like to detect that the config file is messed up. Any suggestions? Thanks

Hello Greg, In the documentation relative to auto configuration [1], one can read: If the configuration file is found but is ill-formed, then logback will detect the error condition and automatically print its internal status on the console. So either the documentation is wrong or logback cannot find your configuration file. In any case, you can instruct logback to print its internal status data with the following code: LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc); See [2] for a full example. HTH [1] http://logback.qos.ch/manual/configuration.html#auto_configuration [2] http://logback.qos.ch/xref/chapter3/MyApp2.html Greg Flex wrote:
Hi All, I was wondering if there is an easy way to test the validity of an XML configuration file. Just as an example I have this now in the config file <blah blah blah> JoranConfigurator doConfigure accepts it and no exception is thrown. Nothing gets printed or written to a file etc. however I'd like to detect that the config file is messed up. Any suggestions? Thanks
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Hi Ceki Gülcü, Thanks for your fast reply. So the problem is that I'm not using the Logback but the Log4j 1.3 alpha 8 version that also has JoranConfigurator object. (author: Curt Arnold, Ceki Gülcü<http://www.qos.ch/log4j/> ) I thought I ask you since you've written it and you more likely to reply to my message from this forum. I'm looking at the (Log4j 1.3 alpha 8) API and don't see any LoggerContext object there. I have at the moment this in my class: public someConstructor(String className, String propertyFile) { //Reads the configuration file. if (!configFile.endsWith("xml") || configFile == ""){ throw new InvalidParameterException("Invalid XML property file."); } logger = org.apache.log4j.Logger.getLogger(className); JoranConfigurator jc = new JoranConfigurator(); jc.doConfigure(configFile, LogManager.getLoggerRepository()); } This will always work even if I pass in my config file <blah blah blah/> Nothing will happen, that is, no exception and no log will be printed. (written etc.) Any other suggestions? I know this isn't the log4j forum..... Thanks Gregory. There's no such thing as LoggerContext or a method On Wed, Mar 18, 2009 at 1:44 PM, Ceki Gulcu <ceki@qos.ch> wrote:
Hello Greg,
In the documentation relative to auto configuration [1], one can read:
If the configuration file is found but is ill-formed, then logback will detect the error condition and automatically print its internal status on the console.
So either the documentation is wrong or logback cannot find your configuration file. In any case, you can instruct logback to print its internal status data with the following code:
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc);
See [2] for a full example.
HTH
[1] http://logback.qos.ch/manual/configuration.html#auto_configuration [2] http://logback.qos.ch/xref/chapter3/MyApp2.html
Greg Flex wrote:
Hi All, I was wondering if there is an easy way to test the validity of an XML configuration file. Just as an example I have this now in the config file <blah blah blah> JoranConfigurator doConfigure accepts it and no exception is thrown. Nothing gets printed or written to a file etc. however I'd like to detect that the config file is messed up. Any suggestions? Thanks
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Hello Greg, I have not looked at log4j 1.3 code for a long time. Here is some code that will probably do what you want: // code for log4j 1.3 and not logback logger = org.apache.log4j.Logger.getLogger(className); JoranConfigurator jc = new JoranConfigurator(); jc.doConfigure(configFile, LogManager.getLoggerRepository()); ExecutionContext ec = jc.getExecutionContext(); for(Object o: ec.getErrorList()) { System.out.println(o); } Again the above code is for log4j 1.3 not logback. HTH, Greg Flex wrote:
Hi Ceki Gülcü,
Thanks for your fast reply. So the problem is that I'm not using the Logback but the Log4j 1.3 alpha 8 version that also has JoranConfigurator object. (author: Curt Arnold, Ceki Gülcü <http://www.qos.ch/log4j/>) I thought I ask you since you've written it and you more likely to reply to my message from this forum. I'm looking at the (Log4j 1.3 alpha 8) API and don't see any LoggerContext object there. I have at the moment this in my class:
public someConstructor(String className, String propertyFile) {
//Reads the configuration file. if (!configFile.endsWith("xml") || configFile == ""){ throw new InvalidParameterException("Invalid XML property file."); }
logger = org.apache.log4j.Logger.getLogger(className); JoranConfigurator jc = new JoranConfigurator(); jc.doConfigure(configFile, LogManager.getLoggerRepository()); }
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Ceki Culce, That worked..... Awesome. Thank You. I'd like to ask you another question.... I'd like to use Logback instead of Log4j however Log4j server along with Log4cxx client and with SocketAppender "understand" each other. That is, I can log with log4j Server messages (with the SocketAppender) that are coming from the Log4cxx clients and of course log4j clients. Then, I can write all these log messages to just one file on a server where my Log4j server is running. This is what I'm really after. I know that Log4j, and I assume also logback as well, has JMSAppender. I don't know that much (yet) about JMS but I wonder if there's a way to use it to write messages coming from C++ client, Java or whatever client we may have.... (I know I need to handle Flex clients as well, Oh man!) I know you more knowledgeble in this area........ Please let me know if there is a way to "capture" all these different log messages coming from different clients somehow and persist them to one repository (like a DB or a flat txt file) Thanks Greg. On Wed, Mar 18, 2009 at 2:39 PM, Ceki Gulcu <ceki@qos.ch> wrote:
Hello Greg,
I have not looked at log4j 1.3 code for a long time. Here is some code that will probably do what you want:
// code for log4j 1.3 and not logback logger = org.apache.log4j.Logger.getLogger(className); JoranConfigurator jc = new JoranConfigurator(); jc.doConfigure(configFile, LogManager.getLoggerRepository()); ExecutionContext ec = jc.getExecutionContext(); for(Object o: ec.getErrorList()) { System.out.println(o); }
Again the above code is for log4j 1.3 not logback.
HTH,
Greg Flex wrote:
Hi Ceki Gülcü,
Thanks for your fast reply. So the problem is that I'm not using the Logback but the Log4j 1.3 alpha 8 version that also has JoranConfigurator object. (author: Curt Arnold, Ceki Gülcü < http://www.qos.ch/log4j/>) I thought I ask you since you've written it and you more likely to reply to my message from this forum. I'm looking at the (Log4j 1.3 alpha 8) API and don't see any LoggerContext object there. I have at the moment this in my class:
public someConstructor(String className, String propertyFile) { //Reads the configuration file. if (!configFile.endsWith("xml") || configFile == ""){ throw new InvalidParameterException("Invalid XML property file."); } logger = org.apache.log4j.Logger.getLogger(className); JoranConfigurator jc = new JoranConfigurator(); jc.doConfigure(configFile, LogManager.getLoggerRepository()); }
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Greg, If I remember correctly, you already had log4cxx write to a log4j SocketServer using XML layout. You can do the same with logback's log4j compatible XMLLayout. See [1] for more information. HTH, [1] http://logback.qos.ch/manual/layouts.html#log4jXMLLayout Greg Flex wrote:
Ceki Culce,
That worked..... Awesome. Thank You. I'd like to ask you another question.... I'd like to use Logback instead of Log4j however Log4j server along with Log4cxx client and with SocketAppender "understand" each other. That is, I can log with log4j Server messages (with the SocketAppender) that are coming from the Log4cxx clients and of course log4j clients. Then, I can write all these log messages to just one file on a server where my Log4j server is running. This is what I'm really after. I know that Log4j, and I assume also logback as well, has JMSAppender. I don't know that much (yet) about JMS but I wonder if there's a way to use it to write messages coming from C++ client, Java or whatever client we may have.... (I know I need to handle Flex clients as well, Oh man!) I know you more knowledgeble in this area........ Please let me know if there is a way to "capture" all these different log messages coming from different clients somehow and persist them to one repository (like a DB or a flat txt file) Thanks Greg.
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Ceki Culce,Yes, you're absolutely right. I do have log4cxx and log4j clients write to the same log4j SocketServer but things got little bit more complicated since the front-end of my app (a friend of mine is working on it) will be written in Adobe Flex. I'd like to be able to get anything an end-user does, whether he/she clicks on the "OK" button or a "Cancel" button or move some kind of slider to a different position etc. I'd like to capture this "event", log it by sending it to the same server that takes all the log messages from all the clients I have (C++, java and Flex) and writes them all to just one (in a perfect scenario) Rollover File Appender. As you know (you've written it ;-) Log4j or Logback has such appender already and I'm trying to utilize it. I'm not sure though if this is possible without running two or so servers that write to two different files. (something I'd like to avoid) Thanks for asking and letting me know about the log4j compatible XMLLayout I Appreciate, Greg On Wed, Mar 18, 2009 at 4:04 PM, Ceki Gulcu <ceki@qos.ch> wrote:
Greg,
If I remember correctly, you already had log4cxx write to a log4j SocketServer using XML layout. You can do the same with logback's log4j compatible XMLLayout. See [1] for more information.
HTH,
[1] http://logback.qos.ch/manual/layouts.html#log4jXMLLayout
Greg Flex wrote:
Ceki Culce,
That worked..... Awesome. Thank You. I'd like to ask you another question.... I'd like to use Logback instead of Log4j however Log4j server along with Log4cxx client and with SocketAppender "understand" each other. That is, I can log with log4j Server messages (with the SocketAppender) that are coming from the Log4cxx clients and of course log4j clients. Then, I can write all these log messages to just one file on a server where my Log4j server is running. This is what I'm really after. I know that Log4j, and I assume also logback as well, has JMSAppender. I don't know that much (yet) about JMS but I wonder if there's a way to use it to write messages coming from C++ client, Java or whatever client we may have.... (I know I need to handle Flex clients as well, Oh man!) I know you more knowledgeble in this area........ Please let me know if there is a way to "capture" all these different log messages coming from different clients somehow and persist them to one repository (like a DB or a flat txt file) Thanks Greg.
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (2)
-
Ceki Gulcu
-
Greg Flex