Package net.sf.logsaw.core.field

Examples of net.sf.logsaw.core.field.LogEntry


    Assert.isNotNull(log, "log"); //$NON-NLS-1$
    Assert.isNotNull(input, "input"); //$NON-NLS-1$
    Assert.isNotNull(collector, "collector"); //$NON-NLS-1$
    Assert.isTrue(isConfigured(), "Dialect should be configured by now"); //$NON-NLS-1$
    try {
      LogEntry currentEntry = null;
      IHasEncoding enc = (IHasEncoding) log.getAdapter(IHasEncoding.class);
      IHasLocale loc = (IHasLocale) log.getAdapter(IHasLocale.class);
      if (loc != null) {
        // Apply the locale
        getPatternTranslator().applyLocale(loc.getLocale(), rules);
      }
      IHasTimeZone tz = (IHasTimeZone) log.getAdapter(IHasTimeZone.class);
      if (tz != null) {
        // Apply the timezone
        getPatternTranslator().applyTimeZone(tz.getTimeZone(), rules);
      }
      LineIterator iter = IOUtils.lineIterator(input, enc.getEncoding());
      int minLinesPerEntry = getPatternTranslator().getMinLinesPerEntry();
      int lineNo = 0;
      int moreLinesToCome = 0;
      try {
        String line = null;
        while (iter.hasNext()) {
          lineNo++;
         
          if (minLinesPerEntry == 1) {
            // Simple case
            line = iter.nextLine();
          } else {
            String s = iter.nextLine();
            if (moreLinesToCome == 0) {
              Matcher m = getInternalPatternFirstLine().matcher(s);
              if (m.find()) {
                // First line
                line = s;
                moreLinesToCome = minLinesPerEntry - 1;
                continue;
              } else {
                // Some crazy stuff
                line = s;
              }
            } else if (iter.hasNext() && (moreLinesToCome > 1)) {
              // Some middle line
              line += IOUtils.LINE_SEPARATOR + s;
              moreLinesToCome--;
              continue;
            } else {
              // Last line
              line += IOUtils.LINE_SEPARATOR + s;
              if (!iter.hasNext()) {
                line += IOUtils.LINE_SEPARATOR;
              }
              moreLinesToCome = 0;
            }
          }
         
          // Error handling
          List<IStatus> statuses = null;
          boolean fatal = false; // determines whether to interrupt parsing
         
          Matcher m = getInternalPatternFull().matcher(line);
          if (m.find()) {
            // The next line matches, so flush the previous entry and continue
            if (currentEntry != null) {
              collector.collect(currentEntry);
              currentEntry = null;
            }
            currentEntry = new LogEntry();
            for (int i = 0; i < m.groupCount(); i++) {
              try {
                getPatternTranslator().extractField(currentEntry, getRules().get(i),
                    m.group(i + 1));
              } catch (CoreException e) {
                // Mark for interruption
                fatal = fatal || e.getStatus().matches(IStatus.ERROR);
               
                // Messages will be displayed later
                if (statuses == null) {
                  statuses = new ArrayList<IStatus>();
                }
                if (e.getStatus().isMultiStatus()) {
                  Collections.addAll(statuses, e.getStatus().getChildren());
                } else {
                  statuses.add(e.getStatus());
                }
              }
            }
           
            // We encountered errors or warnings
            if (statuses != null && !statuses.isEmpty()) {
              currentEntry = null; // Stop propagation
              IStatus status = new MultiStatus(PatternDialectPlugin.PLUGIN_ID,
                  0, statuses.toArray(new IStatus[statuses.size()]),
                  NLS.bind(Messages.APatternDialect_error_failedToParseLine, lineNo), null);
              if (fatal) {
                // Interrupt parsing in case of error
                throw new CoreException(status);
              } else {
                collector.addMessage(status);
              }
            }
          } else if (currentEntry != null) {
            // Append to message
            String msg = currentEntry.get(getFieldProvider().getMessageField());
            currentEntry.put(getFieldProvider().getMessageField(), msg + IOUtils.LINE_SEPARATOR + line);
          }
         
          if (collector.isCanceled()) {
            // Cancel parsing
            break;
View Full Code Here


    Assert.isNotNull(log, "log"); //$NON-NLS-1$
    Assert.isNotNull(input, "input"); //$NON-NLS-1$
    Assert.isNotNull(collector, "collector"); //$NON-NLS-1$
    Assert.isTrue(isConfigured(), "Dialect should be configured by now"); //$NON-NLS-1$
    try {
      LogEntry currentEntry = null;
      IHasEncoding enc = (IHasEncoding) log.getAdapter(IHasEncoding.class);
      IHasLocale loc = (IHasLocale) log.getAdapter(IHasLocale.class);
      // WebSphere Dialect doesn't need to care about the timezone, because it is encoded in the log messages
      DateFormat df = getDateFormat(loc.getLocale());
      LineIterator iter = IOUtils.lineIterator(input, enc.getEncoding());
      int lineNo = 0;
      try {
        while (iter.hasNext()) {
          // Error handling
          lineNo++;
          List<IStatus> statuses = null;
          boolean fatal = false; // determines whether to interrupt parsing
         
          String line = iter.nextLine();
          Matcher m = getInternalPattern().matcher(line);
          if (m.find()) {
            // The next line matches, so flush the previous entry and continue
            if (currentEntry != null) {
              collector.collect(currentEntry);
              currentEntry = null;
            }
            currentEntry = new LogEntry();
            for (int i = 0; i < m.groupCount(); i++) {
              try {
                extractField(currentEntry, i + 1, m.group(i + 1), df);
              } catch (CoreException e) {
                // Mark for interruption
                fatal = fatal || e.getStatus().matches(IStatus.ERROR);
               
                // Messages will be displayed later
                if (statuses == null) {
                  statuses = new ArrayList<IStatus>();
                }
                if (e.getStatus().isMultiStatus()) {
                  Collections.addAll(statuses, e.getStatus().getChildren());
                } else {
                  statuses.add(e.getStatus());
                }
              }
            }
           
            // We encountered errors or warnings
            if (statuses != null && !statuses.isEmpty()) {
              currentEntry = null; // Stop propagation
              IStatus status = new MultiStatus(WebsphereDialectPlugin.PLUGIN_ID,
                  0, statuses.toArray(new IStatus[statuses.size()]),
                  NLS.bind(Messages.WebsphereDialect_error_failedToParseLine, lineNo), null);
              if (fatal) {
                // Interrupt parsing in case of error
                throw new CoreException(status);
              } else {
                collector.addMessage(status);
              }
            }
          } else if (currentEntry != null) {
            // Append to message
            String msg = currentEntry.get(getFieldProvider().getMessageField());
            StringWriter strWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(strWriter);
            printWriter.print(msg);
            printWriter.println();
            printWriter.print(line);
            currentEntry.put(getFieldProvider().getMessageField(), strWriter.toString());
          }
         
          if (collector.isCanceled()) {
            // Cancel parsing
            break;
View Full Code Here

   * @see org.xml.sax.helpers.XMLFilterImpl#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
   */
  @Override
  public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    if (uri.equals(NAMESPACE_LOG4J) && localName.equals(ELEMENT_EVENT)) {
      currentEntry = new LogEntry();
      currentEntry.put(Log4JFieldProvider.FIELD_LOGGER, atts.getValue(ATTRIBUTE_LOGGER));
      currentEntry.put(Log4JFieldProvider.FIELD_TIMESTAMP,
          new Date(Long.parseLong(atts.getValue(ATTRIBUTE_TIMESTAMP))));
      currentEntry.put(Log4JFieldProvider.FIELD_LEVEL,
          Log4JFieldProvider.FIELD_LEVEL.getLevelProvider().findLevel(atts.getValue(ATTRIBUTE_LEVEL)));
View Full Code Here

  private void collectHits(IndexSearcher searcher, TopDocs hits,
      ILogDialect dialect, List<LogEntry> result) throws IOException {
    for (int i = 0; i < hits.scoreDocs.length; i++) {
      final Document doc = searcher.doc(hits.scoreDocs[i].doc);
      final LogEntry entry = new LogEntry();
     
      // 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) {
          String value = doc.get(fld.getKey());
          if (value != null) {
            entry.put(fld, fld.fromIndexedValue(value));
          }
        }

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.LevelLogEntryField)
         */
        @Override
        public void visit(LevelLogEntryField fld) {
          String value = doc.get(fld.getKey());
          if (value != null) {
            entry.put(fld, fld.fromIndexedValue(value));
          }
        }

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.DateLogEntryField)
         */
        @Override
        public void visit(DateLogEntryField fld) {
          String value = doc.get(fld.getKey());
          if (value != null) {
            entry.put(fld, fld.fromIndexedValue(value));
         
        }
      };
      for (ALogEntryField<?, ?> field : dialect.getFieldProvider().getAllFields()) {
        field.visit(visitor);
View Full Code Here

   */
  @Override
  public Image getColumnImage(Object element, int columnIndex) {
    if ((columnIndex == 0) && (log.getDialect().getFieldProvider().getLevelField() != null)) {
      // The icon column
      LogEntry entry = (LogEntry) element;
      Level level = entry.get(log.getDialect().getFieldProvider().getLevelField());
      String iconPath = log.getDialect().getFieldProvider().getLevelField().getLevelProvider().getIconPathForLevel(level);
      if (iconPath != null) {
        // Lookup icon in local image registry
        return getImageFromRegistry(iconPath);
      }
View Full Code Here

  public String getColumnText(Object element, int columnIndex) {
    if (columnIndex == 0) {
      // The icon column
      return ""; //$NON-NLS-1$
    }
    final LogEntry entry = (LogEntry) element;
    if ((columnIndex - 1) < fields.length) {
      final String[] ret = new String[1];
      // 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) {
          String value = entry.get(fld);
          if (value != null) {
            ret[0] = snipAtLinebreak(fld.toInputValue(value, log));
          }
        }

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.LevelLogEntryField)
         */
        @Override
        public void visit(LevelLogEntryField fld) {
          Level value = entry.get(fld);
          if (value != null) {
            ret[0] = fld.toInputValue(value, log);
          }
        }

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.DateLogEntryField)
         */
        @Override
        public void visit(DateLogEntryField fld) {
          Date value = entry.get(fld);
          if (value != null) {
            ret[0] = fld.toInputValue(value, log);
          }
        }
      };
View Full Code Here

   * @see net.sf.logsaw.ui.editors.ILogViewEditor#getFocusCellText()
   */
  @Override
  public String getFocusCellText() {
    ALogEntryField<?, ?> fld = getFocusCellLogEntryField();
    final LogEntry entry = getSelectedLogEntry();
    if ((fld == null) || (entry == null)) {
      return ""; //$NON-NLS-1$
    }
    final String[] ret = new String[1];
    // 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) {
        String value = entry.get(fld);
        if (value != null) {
          ret[0] = fld.toInputValue(value, getLogResource());
        }
      }

      /* (non-Javadoc)
       * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.LevelLogEntryField)
       */
      @Override
      public void visit(LevelLogEntryField fld) {
        Level value = entry.get(fld);
        if (value != null) {
          ret[0] = fld.toInputValue(value, getLogResource());
        }
      }

      /* (non-Javadoc)
       * @see net.sf.logsaw.core.model.ILogEntryFieldVisitor#visit(net.sf.logsaw.core.model.DateLogEntryField)
       */
      @Override
      public void visit(DateLogEntryField fld) {
        Date value = entry.get(fld);
        if (value != null) {
          ret[0] = fld.toInputValue(value, getLogResource());
        }
      }
    };
View Full Code Here

TOP

Related Classes of net.sf.logsaw.core.field.LogEntry

Copyright © 2018 www.massapicom. 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.