logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: logging-log4j/tests/src/java/org/apache/log4j/db DBReeceiverTest.java
Date Wed, 12 May 2004 20:05:39 GMT
ceki        2004/05/12 13:05:39

  Modified:    src/java/org/apache/log4j/db/dialect mysql.sql
               src/java/org/apache/log4j/joran JoranConfigurator.java
               tests/src/java/org/apache/log4j/db DBReeceiverTest.java
  Added:       tests/input/db dbAppender1.xml dbReceiver1.xml
  Log:
  - Small fixes/additions of useful riles to Joran. It can now start living up 
  to expectations.
  - Small fixes
  - DBReceiver can be configured through Joran.
  
  Revision  Changes    Path
  1.1                  logging-log4j/tests/input/db/dbAppender1.xml
  
  Index: dbAppender1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE log4j:configuration>
  
  <!-- This file is used to test DBAppender. It assumes the existence of a local 
    MySQL or PostgreSQL databases.
  	  -->
  	  
  <log4j:configuration debug="true">
  	  
    <plugin name="DB1" class="org.apache.log4j.db.DBAppender">
       <connectionSource class="org.apache.log4j.db.DBReceiver">
         <param name="driverClass" value="com.mysql.jdbc.Driver"/>
         <param name="url" value="jdbc:mysql:///test"/>
         <param name="user" value="root"/>
       </connectionSource>
    </plugin>
  
  
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
       <layout class="org.apache.log4j.PatternLayout"/>
         <param name="ConversionPattern" value="%relative %level %logger - %message%n"/>
       </layout>
    </appender>
    
  <!--
     <appender name="CS" class="org.apache.log4j.chainsaw.ChainsawAppender">
    </appender>
    -->
    <root>
      <level value ="debug"/>
      <appender-ref ref="CONSOLE" />
    </root>  
  </log4j:configuration>
  
  
  
  
  
  
  1.1                  logging-log4j/tests/input/db/dbReceiver1.xml
  
  Index: dbReceiver1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE log4j:configuration>
  
  <!-- This file is used to test DBAppender. It assumes the existence of a local 
    MySQL or PostgreSQL databases.
  	  -->
  	  
  <log4j:configuration debug="true">
  	  
    <plugin name="DB1" class="org.apache.log4j.db.DBReceiver">
       <connectionSource class="org.apache.log4j.db.UrlConnectionSource">
         <param name="driverClass" value="com.mysql.jdbc.Driver"/>
         <param name="url" value="jdbc:mysql:///test"/>
         <param name="user" value="root"/>
       </connectionSource>
    </plugin>
  
  
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="CON %relative %level %logger - %message%n"/>
       </layout>
    </appender>
    
    <root>
      <level value ="debug"/>
      <appender-ref ref="CONSOLE" />
    </root>  
  </log4j:configuration>
  
  
  
  
  
  
  1.7       +2 -2      logging-log4j/src/java/org/apache/log4j/db/dialect/mysql.sql
  
  Index: mysql.sql
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/dialect/mysql.sql,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- mysql.sql	12 May 2004 14:59:53 -0000	1.6
  +++ mysql.sql	12 May 2004 20:05:39 -0000	1.7
  @@ -34,7 +34,7 @@
       mapped_key        VARCHAR(254) NOT NULL,
       mapped_value      VARCHAR(254),
       PRIMARY KEY(event_id, mapped_key),
  -    FOREIGN KEY (event_id) REFERENCES logging_event(id)
  +    FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
     );
   COMMIT;
   
  @@ -45,6 +45,6 @@
       i                SMALLINT NOT NULL,
       trace_line       VARCHAR(254) NOT NULL,
       PRIMARY KEY(event_id, i),
  -    FOREIGN KEY (event_id) REFERENCES logging_event(id)
  +    FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
     );
   COMMIT;
  
  
  
  1.6       +7 -1      logging-log4j/src/java/org/apache/log4j/joran/JoranConfigurator.java
  
  Index: JoranConfigurator.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/joran/JoranConfigurator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JoranConfigurator.java	12 May 2004 19:39:14 -0000	1.5
  +++ JoranConfigurator.java	12 May 2004 20:05:39 -0000	1.6
  @@ -30,6 +30,8 @@
   import org.apache.joran.Interpreter;
   import org.apache.joran.Pattern;
   import org.apache.joran.RuleStore;
  +import org.apache.joran.action.NestComponentIA;
  +import org.apache.joran.action.NewRuleAction;
   import org.apache.joran.action.ParamAction;
   import org.apache.joran.helper.SimpleRuleStore;
   import org.apache.log4j.helpers.LogLog;
  @@ -120,9 +122,13 @@
       rs.addRule(new Pattern("log4j:configuration/appender/layout"), new LayoutAction());
       rs.addRule(new Pattern("log4j:configuration/appender/layout/conversionRule"), new ConversionRuleAction());
       rs.addRule(new Pattern("log4j:configuration/plugin"), new PluginAction());
  +    rs.addRule(new Pattern("log4j:configuration/newRule"), new NewRuleAction());
       rs.addRule(new Pattern("*/param"), new ParamAction());
   
       joranInterpreter = new Interpreter(rs);
  +    
  +    // The following line adds the capability to parse nested components
  +    joranInterpreter.addImplcitAction(new NestComponentIA());
       ExecutionContext ec = joranInterpreter.getExecutionContext();
   
       HashMap omap = ec.getObjectMap();
  @@ -138,7 +144,7 @@
       try {
         SAXParserFactory spf = SAXParserFactory.newInstance();
         SAXParser saxParser = spf.newSAXParser();
  -      saxParser.parse("file:input/joran/parser2.xml", joranInterpreter);
  +      saxParser.parse(in, joranInterpreter);
       } catch (SAXException e) {
         // all exceptions should have been recorded already.
       } catch (ParserConfigurationException pce) {
  
  
  
  1.2       +41 -21    logging-log4j/tests/src/java/org/apache/log4j/db/DBReeceiverTest.java
  
  Index: DBReeceiverTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/db/DBReeceiverTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DBReeceiverTest.java	12 May 2004 15:39:03 -0000	1.1
  +++ DBReeceiverTest.java	12 May 2004 20:05:39 -0000	1.2
  @@ -15,6 +15,8 @@
    */
   package org.apache.log4j.db;
   
  +import java.io.BufferedReader;
  +import java.io.InputStreamReader;
   import java.util.Hashtable;
   
   import javax.naming.Context;
  @@ -25,6 +27,8 @@
   import org.apache.log4j.BasicConfigurator;
   import org.apache.log4j.LogManager;
   import org.apache.log4j.helpers.LogLog;
  +import org.apache.log4j.joran.JoranConfigurator;
  +
   
   /**
    * @author Ceki G&uuml;lc&uuml;
  @@ -57,28 +61,44 @@
       super(arg0);
     }
   
  -  public void testBasic() {
  -    BasicConfigurator.configure();
  -    LogLog.info("asdasd");
  -
  -    UrlConnectionSource connectionSource = new UrlConnectionSource();
  -    connectionSource.setDriverClass("com.mysql.jdbc.Driver");
  -    connectionSource.setUrl("jdbc:mysql:///test");
  -    connectionSource.setUser("root");
  -    LogLog.info("xxxxxxx");
  -
  -    DBReceiver dbReceiver = new DBReceiver();
  -    dbReceiver.setLoggerRepository(LogManager.getLoggerRepository());
  -    dbReceiver.setConnectionSource(connectionSource);
  -    dbReceiver.activateOptions();
  -    LogLog.info("after  dbReceiver.activateOptions()");
  -
  -    
  - 
  -    try { Thread.sleep(3000); } catch(Exception e) {}
  -    dbReceiver.shutdown();
  +  public void testBasic()
  +         throws Exception {
  +
  +    //BasicConfigurator.configure();
  +    JoranConfigurator jc = new JoranConfigurator();
  +    LogLog.info("----");
  +    jc.doConfigure("input/db/dbReceiver1.xml", LogManager.getLoggerRepository());
  +
  +
  +//    UrlConnectionSource connectionSource = new UrlConnectionSource();
  +//    connectionSource.setDriverClass("com.mysql.jdbc.Driver");
  +//    connectionSource.setUrl("jdbc:mysql:///test");
  +//    connectionSource.setUser("root");
  +//    LogLog.info("xxxxxxx");
  +//
  +//    DBReceiver dbReceiver = new DBReceiver();
  +//    dbReceiver.setLoggerRepository(LogManager.getLoggerRepository());
  +//    dbReceiver.setConnectionSource(connectionSource);
  +//    dbReceiver.activateOptions();
  +//    LogLog.info("after  dbReceiver.activateOptions()");
  +
  +//    try {
  +//      Thread.sleep(3000);
  +//    } catch (Exception e) {
  +//    }
  +    //dbReceiver.shutdown();
       LogLog.info("after  dbReceiver.shutdown()");
  -    try { Thread.sleep(3000); } catch(Exception e) {}
  +
  +    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  +
  +    while (true) {
  +      System.out.println("Type a message to send to log server. Type 'q' to quit.");
  +      String s = reader.readLine();
  +      if (s.equals("q")) {
  +        break;
  +      } else {
  +      }
  +    }
     }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message