Author: seb
Date: Thu Nov  9 09:50:06 2006
New Revision: 888

Added:
   
logback/trunk/logback-examples/src/main/java/chapter4/db/append-and-share-with-jndi.xml
      - copied unchanged from r883, 
/logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml
Removed:
   logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml
Modified:
   
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
   logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-syslog.xml
   logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml

Log:
on going work on chapter 4
- SyslogAppender config (yet to be tested in real life)
- Modified SyslogAppenderTest, progress need to be done here, on 
testWithExceptions

Modified: 
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
==============================================================================
--- 
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
      (original)
+++ 
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
      Thu Nov  9 09:50:06 2006
@@ -30,7 +30,7 @@
   }
 
   public void testBasic() throws InterruptedException {
-      int port = MockSyslogServer.PORT+1;
+    int port = MockSyslogServer.PORT + 1;
 
     MockSyslogServer mockServer = new MockSyslogServer(1, port);
     mockServer.start();
@@ -44,35 +44,37 @@
     sa.setSyslogHost("localhost");
     sa.setFacility("MAIL");
     sa.setPort(port);
+    sa.setSuffixPattern("[%thread] %logger %msg %exception");
     sa.start();
     assertTrue(sa.isStarted());
-    
+
     String loggerName = this.getClass().getName();
     Logger logger = lc.getLogger(loggerName);
     logger.addAppender(sa);
     String logMsg = "hello";
     logger.debug(logMsg);
     StatusPrinter.print(lc.getStatusManager());
-    
+
     // wait max 2 seconds for mock server to finish. However, it should
     // much sooner than that.
     mockServer.join(8000);
     assertTrue(mockServer.finished);
     assertEquals(1, mockServer.msgList.size());
     String msg = mockServer.msgList.get(0);
-   
-    String expected = 
"<"+(SyslogConstants.LOG_MAIL+SyslogConstants.DEBUG_SEVERITY)+">";
+
+    String expected = "<"
+        + (SyslogConstants.LOG_MAIL + SyslogConstants.DEBUG_SEVERITY) + ">";
     assertTrue(msg.startsWith(expected));
 
     String first = "<\\d{2}>\\w{3} \\d{2} \\d{2}(:\\d{2}){2} \\w* ";
     String threadName = Thread.currentThread().getName();
-   
-    assertTrue(msg.matches(first +"\\["+threadName+"\\] "+ loggerName +" " 
+logMsg));
-   
- }
-  
-  public void testExceptoin() throws InterruptedException {
-      int port = MockSyslogServer.PORT+2;
+    assertTrue(msg.matches(first + "\\[" + threadName + "\\] " + loggerName
+        + " " + logMsg + " "));
+
+  }
+
+  public void testException() throws InterruptedException {
+    int port = MockSyslogServer.PORT + 2;
     MockSyslogServer mockServer = new MockSyslogServer(1, port);
     mockServer.start();
     // give MockSyslogServer head start
@@ -85,31 +87,36 @@
     sa.setSyslogHost("localhost");
     sa.setFacility("MAIL");
     sa.setPort(port);
+    sa.setSuffixPattern("[%thread] %logger %msg %exception");
     sa.start();
     assertTrue(sa.isStarted());
-    
+
     String loggerName = this.getClass().getName();
     Logger logger = lc.getLogger(loggerName);
     logger.addAppender(sa);
     String logMsg = "hello";
-    logger.debug(logMsg, new Exception("just testing"));
+    String exMsg = "just testing";
+    Exception ex = new Exception(exMsg);
+    logger.debug(logMsg, ex);
     StatusPrinter.print(lc.getStatusManager());
-    
+
     // wait max 2 seconds for mock server to finish. However, it should
     // much sooner than that.
     mockServer.join(8000);
     assertTrue(mockServer.finished);
     assertEquals(1, mockServer.msgList.size());
     String msg = mockServer.msgList.get(0);
-   
-    String expected = 
"<"+(SyslogConstants.LOG_MAIL+SyslogConstants.DEBUG_SEVERITY)+">";
+
+    String expected = "<"
+        + (SyslogConstants.LOG_MAIL + SyslogConstants.DEBUG_SEVERITY) + ">";
     assertTrue(msg.startsWith(expected));
 
-    //String first = "<\\d{2}>\\w{3} \\d{2} \\d{2}(:\\d{2}){2} \\w* ";
-    //String threadName = Thread.currentThread().getName();
-    System.out.println(msg);
-    //assertTrue(msg.matches(first +"\\["+threadName+"\\] "+ loggerName +" " 
+logMsg));
-   
-    //fail("check exceptions");
+//    String first = "<\\d{2}>\\w{3} \\d{2} \\d{2}(:\\d{2}){2} \\w* ";
+//    String threadName = Thread.currentThread().getName();
+//    String expectedResult = first + "\\[" + threadName + "\\] " + loggerName
+//        + " " + logMsg + " " + ex.getClass().getCanonicalName() + ": " + 
exMsg + "\n";
+//    assertTrue(msg.matches(expectedResult));
+
+    // fail("check exceptions");
   }
 }

Modified: 
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-syslog.xml
==============================================================================
--- 
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-syslog.xml   
    (original)
+++ 
logback/trunk/logback-examples/src/main/java/chapter4/conf/logback-syslog.xml   
    Thu Nov  9 09:50:06 2006
@@ -1,10 +1,10 @@
 <configuration>
 
-  <appender name="STDOUT"
+  <appender name="SYSLOG"
     class="ch.qos.logback.classic.net.SyslogAppender">
     <SyslogHost>pixie</SyslogHost>
     <Facility>AUTH</Facility>
-    <SuffixPattern>%-4relative [%thread] %-5level - %msg %n</SuffixPattern>
+    <SuffixPattern>%-4relative [%thread] %-5level - %msg</SuffixPattern>
   </appender>
 
   <root>

Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml      
(original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml      
Thu Nov  9 09:50:06 2006
@@ -2035,6 +2035,33 @@
                        single configuration file and shared by logback and 
other frameworks.
                </p>    
                
+                               
+               <p>
+                       The connection created by 
<code>DataSourceConnectionSource</code> can be placed in a JNDI
+                       context by using 
<code>BindDataSourceToJNDIAction</code>. In that case, one has to specify
+                       the use of this class by adding a new rule to Joran, 
logback's configuration framework. Here
+                       is an excerpt of such a configuration file.
+               </p>
+               
+<div class="source"><pre>&lt;configuration>
+  ..
+  <b>&lt;newRule pattern="configuration/bindDataSourceToJNDI" 
+           actionClass="ch.qos.logback.core.db.BindDataSourceToJNDIAction"/>
+           
+  &lt;bindDataSourceToJNDI /></b>
+  ..
+&lt;/configuration></pre></div>
+
+               <p>
+                       The <em>newRule</em> element teaches Joran to use 
specified action class with the given pattern.
+                       Then, we simply declare the given element. The action 
class will be called and our connection
+                       source will be bound to a JNDI context.
+               </p>
+               <p>
+                       This is a very powerfull possibility of Joran. If you'd 
like to read more about Joran, please
+                       visit our <a href="../joran.html">introduction to 
Joran</a>.
+               </p>
+
                <p>
                        The third implementation of 
<code>ConnectionSource</code> that is shipped with
                        logback is the <code>JNDIConnectionSource</code>.
@@ -2054,13 +2081,11 @@
                        application server provides.
                </p>
                
-<div class="source"><pre>
-&lt;connectionSource 
class=&quot;ch.qos.logback.core.db.JNDIConnectionSource&quot;&gt;
+<div class="source"><pre>&lt;connectionSource 
class=&quot;ch.qos.logback.core.db.JNDIConnectionSource&quot;&gt;
   &lt;param name=&quot;jndiLocation&quot; value=&quot;jdbc/MySQLDS&quot; /&gt;
   &lt;param name=&quot;username&quot; value=&quot;myUser&quot; /&gt;
   &lt;param name=&quot;password&quot; value=&quot;myPassword&quot; /&gt;
-&lt;/connectionSource&gt;
- </pre></div>
+&lt;/connectionSource&gt;</pre></div>
 
                <p>
                        Note that this class will obtain an
@@ -2073,12 +2098,6 @@
                </p>
 
 
-               <p>
-                       <b>MORE INFO TO ADD HERE JNDI + BindAction + 
DataSourceCS? Or directly
-                       with JNDICS??</b>
-               </p>
-
-
                <h3>SyslogAppender</h3>
                
                <p>
@@ -2176,13 +2195,36 @@
                </p>
                
                <p>
-                       Since the format of a syslog request follows rather 
strict rules, 
+                       Since the format of a syslog request follows rather 
strict rules, there is no layout
+                       to be used with <code>SyslogAppender</code>. However, 
the using the 
+                       <span class="option">SuffixPattern</span> option lets 
the user display whatever
+                       information she wishes.
                </p>
                
+               <p>
+                       Here is a sample configuration using a 
<code>SyslogAppender</code>.
+               </p>
                
-               
-               
-               
+<div class="source"><pre>&lt;configuration>
+
+  &lt;appender name="SYSLOG"
+    class="ch.qos.logback.classic.net.SyslogAppender">
+    &lt;SyslogHost>remote_home&lt;/SyslogHost>
+    &lt;Facility>AUTH&lt;/Facility>
+    &lt;SuffixPattern>%-4relative [%thread] %-5level - %msg&lt;/SuffixPattern>
+  &lt;/appender>
+
+  &lt;root>
+    &lt;level value="debug" />
+    &lt;appender-ref ref="STDOUT" />
+  &lt;/root>
+&lt;/configuration></pre></div>
+
+               <p>
+                       When testing this configuration, one should verify that 
the remote syslog daemon
+                       accepts TCP requests from an external source. 
Experience shows that syslog daemons
+                       usually deny such requests by default.
+               </p>
                
                
                <h2>Logback Access</h2>
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev

Reply via email to