Examples of ILogEntryCollector


Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

       * @see net.sf.logsaw.index.impl.ARunWithIndexWriter#doRunWithIndexWriter(org.apache.lucene.index.IndexWriter, net.sf.logsaw.core.framework.ILogResource)
       */
      @Override
      protected SynchronizationResult doRunWithIndexWriter(final IndexWriter writer,
          final ILogResource log) throws CoreException {
        ILogEntryCollector collector = new ALogEntryCollector(monitor) {
         
          /* (non-Javadoc)
           * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
           */
          @Override
          protected boolean doCollect(final LogEntry entry)
              throws IOException {
            final Document doc = new Document();
            if (latestEntryDate != null) {
              Date d = entry.get(log.getDialect().getFieldProvider().getTimestampField());
              if (!d.after(latestEntryDate)) {
                // Skip entry because it was already indexed
                return false;
              }
            }
           
            // Setup visitor
            ILogEntryFieldVisitor visitor = new ILogEntryFieldVisitor() {

              /* (non-Javadoc)
               * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.StringLogEntryField)
               */
              @Override
              public void visit(StringLogEntryField fld) {
                // Decide whether to analyze the field
                if (fld.isAnalyzed()) {
                  doc.add(new TextField(fld.getKey(),
                      fld.toIndexedValue(entry.get(fld)),
                      Field.Store.YES));
                } else {
                  doc.add(new StringField(fld.getKey(),
                      fld.toIndexedValue(entry.get(fld)),
                      Field.Store.YES));
                }
              }

              /* (non-Javadoc)
               * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.LevelLogEntryField)
               */
              @Override
              public void visit(LevelLogEntryField fld) {
                Level lvl = entry.get(fld);
                Assert.isTrue(lvl.getValue() > 0, "Level value must be a positive integer"); //$NON-NLS-1$
                doc.add(new IntField(
                    fld.getKey(), fld.toIndexedValue(lvl), Field.Store.YES));
              }

              /* (non-Javadoc)
               * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.DateLogEntryField)
               */
              @Override
              public void visit(DateLogEntryField fld) {
                doc.add(new LongField(
                    fld.getKey(), fld.toIndexedValue(entry.get(fld)), Field.Store.YES));
              }
            };
            for (ALogEntryField<?, ?> fld : log.getDialect().getFieldProvider().getAllFields()) {
              if (entry.contains(fld)) {
                fld.visit(visitor);
              }
            }
            writer.addDocument(doc);
            return true;
          }
        };
       
        if (log.getDialect().getFieldProvider().getTimestampField() == null) {
          // We have no barrier timestamp, so perform truncate to avoid duplicates
          truncate(log, writer);
         
          collector.addMessage(new Status(IStatus.INFO, IndexPlugin.PLUGIN_ID,
              Messages.LuceneIndexService_info_autoTruncate_noTimestampField));
        } else if (!hasDateComponent(log)) {
          // The date format only contains time components, so perform truncate to avoid duplicates
          truncate(log, writer);
         
          collector.addMessage(new Status(IStatus.INFO, IndexPlugin.PLUGIN_ID,
              Messages.LuceneIndexService_info_autoTruncate_noDateComponent));
        }
       
        // Perform synchronize
        log.synchronize(collector, monitor);
        return new SynchronizationResult(monitor.isCanceled(), collector.getTotalCollected(),
            System.currentTimeMillis() - startTime, collector.getMessages());
      }
    };
    return runnable.runWithIndexWriter(log, getAnalyzer(), getMatchVersion());
  }
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("server.10-11-09.log.txt");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      APatternDialect dialect = (APatternDialect) getLogResource().getDialect();
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      try {
        getLogResource().synchronize(coll, null);
        fail("Should throw exception because it is not configured");
      } catch (AssertionFailedException e) {
        // should be configured
      }
      dialect.configure(APatternDialect.OPTION_PATTERN, "%d %-5p [%c] (%t) %m%n");
      getLogResource().synchronize(coll, null);
      assertEquals(4, list.size());
      assertEquals(4, coll.getTotalCollected());
     
      assertEquals("INFO", list.get(1).get(Log4JFieldProvider.FIELD_LEVEL).getName());
      assertEquals("org.apache.coyote.http11.Http11Protocol", list.get(1).get(Log4JFieldProvider.FIELD_LOGGER));
      assertEquals("Starting Coyote HTTP/1.1 on http-0.0.0.0-8080", list.get(1).get(Log4JFieldProvider.FIELD_MESSAGE));
      assertEquals("main", list.get(1).get(Log4JFieldProvider.FIELD_THREAD));
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("server-locinfo.log.txt");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      APatternDialect dialect = (APatternDialect) getLogResource().getDialect();
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      dialect.configure(APatternDialect.OPTION_PATTERN, "%d{ABSOLUTE} %-5p - %m (%F:%M:%L)%n");
      getLogResource().synchronize(coll, null);
      assertEquals(5, list.size());
      assertEquals(5, coll.getTotalCollected());
     
      assertEquals("Creating dependent components for: jboss.system:type=Log4jService,service=Logging dependents are: []", list.get(4).get(Log4JFieldProvider.FIELD_MESSAGE));
      assertEquals("create", list.get(4).get(Log4JFieldProvider.FIELD_LOC_METHOD));
      assertEquals("ServiceController.java", list.get(4).get(Log4JFieldProvider.FIELD_LOC_FILENAME));
      assertEquals("342", list.get(4).get(Log4JFieldProvider.FIELD_LOC_LINE));
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("server-invalidline.log.txt");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      APatternDialect dialect = (APatternDialect) getLogResource().getDialect();
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      dialect.configure(APatternDialect.OPTION_PATTERN, "%d{ABSOLUTE} %-5p - %m (%t)%n");
      getLogResource().synchronize(coll, null);
      assertEquals(4, list.size());
      assertEquals(4, coll.getTotalCollected());
      assertEquals(1, coll.getMessages().size());
    } catch (Exception e) {
      getLogger().error(e.getLocalizedMessage(), e);
      fail("Exception should not occur: " + e.getLocalizedMessage());
    }
  }
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("multiline.log.txt");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      APatternDialect dialect = (APatternDialect) getLogResource().getDialect();
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      dialect.configure(APatternDialect.OPTION_PATTERN, "%d{yyyy-MM-dd HH:mm:ss,SSS} %p %t %x %c%n %m%n%n");
      getLogResource().synchronize(coll, null);
      assertEquals(5, list.size());
      assertEquals(5, coll.getTotalCollected());
     
      assertTrue(list.get(1).get(Log4JFieldProvider.FIELD_MESSAGE).contains("   at FlexNet.SystemServices.ComponentFactory.BusinessComponentMethod.Invoke()"));
      assertEquals("Failed to compute operation. OperationID: 100003399, Result: FlexNet.FunctionInterpreter.BusinessRules.Functions.BusinessComponentResult.UnexpectedErrorWhenTryingToExecuteMethod", list.get(3).get(Log4JFieldProvider.FIELD_MESSAGE));
    } catch (Exception e) {
      getLogger().error(e.getLocalizedMessage(), e);
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("lazy.log.txt");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      APatternDialect dialect = (APatternDialect) getLogResource().getDialect();
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      dialect.configure(APatternDialect.OPTION_PATTERN, "%d %-5p [%c] %m%n");
      getLogResource().synchronize(coll, null);
      assertEquals(3, list.size());
      assertEquals(3, coll.getTotalCollected());
     
      assertEquals("INFO", list.get(0).get(Log4JFieldProvider.FIELD_LEVEL).getName());
      assertEquals("de.docufy.cms.service.transformation.layout.PubInstanceHandler", list.get(0).get(Log4JFieldProvider.FIELD_LOGGER));
      assertEquals("Element: graphic cmsid: fcda5d8c9489a42e0a00206a001baae7:1:--:--:PNG96", list.get(0).get(Log4JFieldProvider.FIELD_MESSAGE));
      assertEquals("ERROR", list.get(1).get(Log4JFieldProvider.FIELD_LEVEL).getName());
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("no-timestamp.log.txt");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      APatternDialect dialect = (APatternDialect) getLogResource().getDialect();
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      dialect.configure(APatternDialect.OPTION_PATTERN, "%p %t %c - %m%n");
      getLogResource().synchronize(coll, null);
      assertEquals(15, list.size());
      assertEquals(15, coll.getTotalCollected());
     
      assertEquals("INFO", list.get(12).get(Log4JFieldProvider.FIELD_LEVEL).getName());
      assertEquals("org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor", list.get(12).get(Log4JFieldProvider.FIELD_LOGGER));
      assertEquals("JSR-330 'javax.inject.Inject' annotation found and supported for autowiring", list.get(12).get(Log4JFieldProvider.FIELD_MESSAGE));
      assertEquals("main", list.get(12).get(Log4JFieldProvider.FIELD_THREAD));
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("websphere_de.log.txt");
      createLogResourceWithPK("UTF-8", Locale.US, getTimeZone());
     
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      try {
        getLogResource().synchronize(coll, null);
        fail("Should not parse because of locale");
      } catch (Exception e) {
        // Expected
      }
     
      // Retry
      createLogResourceWithPK("UTF-8", Locale.GERMANY, getTimeZone());
      getLogResource().synchronize(coll, null);
     
      assertEquals(6, list.size());
      assertEquals(6, coll.getTotalCollected());
     
      assertEquals(1267004712871L, list.get(0).get(WebsphereFieldProvider.FIELD_TIMESTAMP).getTime());
      assertEquals("0000003a", list.get(0).get(WebsphereFieldProvider.FIELD_THREAD_ID));
      assertEquals("DB2CmsService", list.get(0).get(WebsphereFieldProvider.FIELD_SHORT_NAME));
      assertEquals("INFO", list.get(0).get(WebsphereFieldProvider.FIELD_EVENT_TYPE).getName());
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

  public void testBasicParsing() {
    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("server.10-11-09.log.xml");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      getLogResource().synchronize(coll, null);
      assertEquals(4, list.size());
      assertEquals(4, coll.getTotalCollected());
     
      assertEquals("INFO", list.get(1).get(Log4JFieldProvider.FIELD_LEVEL).getName());
      assertEquals("org.apache.coyote.http11.Http11Protocol", list.get(1).get(Log4JFieldProvider.FIELD_LOGGER));
      assertEquals("Starting Coyote HTTP/1.1 on http-0.0.0.0-8080", list.get(1).get(Log4JFieldProvider.FIELD_MESSAGE));
      assertEquals("main", list.get(1).get(Log4JFieldProvider.FIELD_THREAD));
View Full Code Here

Examples of net.sf.logsaw.core.dialect.ILogEntryCollector

  public void testLocInfoParsing() {
    final List<LogEntry> list = new LinkedList<LogEntry>();
    try {
      loadLogFile("server-locinfo.log.xml");
      createLogResourceWithPK("UTF-8", Locale.getDefault(), getTimeZone());
      ILogEntryCollector coll = new ALogEntryCollector(null) {

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.framework.support.ALogEntryCollector#doCollect(net.sf.logsaw.core.model.LogEntry)
         */
        @Override
        protected boolean doCollect(LogEntry entry) throws IOException {
          list.add(entry);
          return true;
        }
      };
      getLogResource().synchronize(coll, null);
      assertEquals(5, list.size());
      assertEquals(5, coll.getTotalCollected());
     
      assertEquals("Creating dependent components for: jboss.system:type=Log4jService,service=Logging dependents are: []", list.get(4).get(Log4JFieldProvider.FIELD_MESSAGE));
      assertEquals("org.jboss.system.ServiceController", list.get(4).get(Log4JFieldProvider.FIELD_LOC_CLASS));
      assertEquals("create", list.get(4).get(Log4JFieldProvider.FIELD_LOC_METHOD));
      assertEquals("ServiceController.java", list.get(4).get(Log4JFieldProvider.FIELD_LOC_FILENAME));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.