Date: 2004-02-19T18:52:39
   Editor: VadimGritsenko <[EMAIL PROTECTED]>
   Wiki: Xindice Wiki
   Page: LoggingwithXindice
   URL: http://wiki.apache.org/xindice/LoggingwithXindice

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -10,18 +10,18 @@
 
 The steps to achieve this are as follows;
 
-* Create addDocument xindice object to write to Xindice: use addDocument.java 
included in Xindice documentation and amend it for our purposes.
+ * Create addDocument xindice object to write to Xindice: use addDocument.java 
included in Xindice documentation and amend it for our purposes.
 
-* Create log4j XindiceAppender: use WriterAppender.java included in Log4J 
documentation and src distribution and amend it for our purposes.
+ * Create log4j XindiceAppender: use WriterAppender.java included in Log4J 
documentation and src distribution and amend it for our purposes.
 
-* define log4j property file: Use an xml log4j property file that attatches 
our new XindiceAppender to log
+ * Define log4j property file: Use an xml log4j property file that attatches 
our new XindiceAppender to log
 
 As noted above, I will hack up the addDocument.java example that comes with 
the xindice documentation. I have placed all my objects in the 
com.example.xindice package.
  
 Firstly we need to have an object that takes care of the writing to Xindice.
 
 <b>addDocument.java</b>
-<pre>
+{{{
 package com.example.xindice;
 
 import org.xmldb.api.base.*;
@@ -33,25 +33,20 @@
 
 public class addDocument {
 
-  /**
-     Log event. */
-       private String _Event= null;
+  /** Log event. */
+  private String _Event= null;
 
-  /**
-     Current server hosting xindice. */
-       private String _Host= null;
+  /** Current server hosting xindice. */
+  private String _Host= null;
 
-  /**
-     Deprecated var. */
-       private String _FileName=null;
+  /** Deprecated var. */
+  private String _FileName=null;
 
-  /**
-     The path of the current collection. */
-       private String _Collection=null;
+  /** The path of the current collection. */
+  private String _Collection=null;
 
-  /**
-     The value to be used for log4j namespace. */
-       private String _Namespace=null;
+  /** The value to be used for log4j namespace. */
+  private String _Namespace=null;
 
 
   public void setEvent(String event) {
@@ -139,7 +134,7 @@
 }
 
 }
-</pre>
+}}}
 
 The write method does all the heavy lifting, with the entry point for the 
logger to use writeEvent. There are set methods for defining the event, 
namespace to use for logger xml, and collection path.
 
@@ -148,7 +143,7 @@
 The next file is the XindiceAppender, its just a hacked up version of 
WriterAppender.java that comes with log4j. WriterAppender wrote event data to a 
file, as previously stated I want to retain this capability, but also add 
writing to Xindice. Log4j can use multiple appenders so this is not neccesary 
in production, though when testing the code I needed to verify that events were 
actually being fired off.
 
 <b>XindiceAppender.java</b>
-<pre>
+{{{
 /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
@@ -571,14 +566,16 @@
     }
  }
 }
-</pre>
+}}}
 
 The code in subAppend() will write the event, set db collection path, 
namespace to be used with xml, and finally fire off writeEvent. 
 
-          xindicedb.setEvent(this.layout.format(event).toString());
-          xindicedb.setCollection(Collection);
-          xindicedb.setNamespace(log4jNamespace);
-          xindicedb.writeEvent();
+{{{
+   xindicedb.setEvent(this.layout.format(event).toString());
+   xindicedb.setCollection(Collection);
+   xindicedb.setNamespace(log4jNamespace);
+   xindicedb.writeEvent();
+}}}
 
 Once again there is plenty of room for optimisation and improvement, though I 
thought breaking them up would assist in understanding the process. The 
additional flags and vars handle the extra requirements of writing to Xindice.
 
@@ -591,15 +588,17 @@
 As with any log4j you will need to invoke the logging code with the 
appropriate configuration.
 OK you will still need to attatch this from within the code that is logging 
something...which is pure log4j stuff;
 
-           Logger root = Logger.getRootLogger();
-           DOMConfigurator.configure("c:\\log4j.properties.xml");
+{{{
+    Logger root = Logger.getRootLogger();
+    DOMConfigurator.configure("c:\\log4j.properties.xml");
+}}}
 
 note- remember to use DOMConfigurator with xml log4j prop files
 
 So lets now show an example property configuration file.
 
 <b>property.xml</b>
-<pre>
+{{{
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
@@ -617,7 +616,7 @@
         <appender-ref ref="myAppender" />
     </root>
 </log4j:configuration>
-</pre>
+}}}
 
 The com.example.xindice.XindiceAppender appender should write to whatever 
collection you have defined in xindice. In the case above, the logger is 
looking for a /db/log collection. Appropriate errors will be thrown for 
malformed xml. 
 
@@ -627,19 +626,13 @@
 
 Improvements for the future could be;
 
-* prescribe xindice xml document name
-* append option to append to existing file 
-* add additional xml meta data 
-* add xslt interception
-* add port option
-* add authentication
-
-good luck, Jim Fuller
-
-
-
-
-
+ * prescribe xindice xml document name
+ * append option to append to existing file 
+ * add additional xml meta data 
+ * add xslt interception
+ * add port option
+ * add authentication
 
+Good luck, Jim Fuller
 
 

Reply via email to