/src/main/java/org/chililog/server/engine/parsers/DefaultEntryParser.java

https://github.com/lightningdb/chililog-server · Java · 106 lines · 39 code · 12 blank · 55 comment · 0 complexity · b06af0230d2353fb2ec6b6aafe0519f3 MD5 · raw file

  1. //
  2. // Copyright 2010 Cinch Logic Pty Ltd.
  3. //
  4. // http://www.chililog.com
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. package org.chililog.server.engine.parsers;
  19. import java.util.ArrayList;
  20. import org.chililog.server.common.ChiliLogException;
  21. import org.chililog.server.common.Log4JLogger;
  22. import org.chililog.server.data.RepositoryEntryBO;
  23. import org.chililog.server.data.RepositoryConfigBO;
  24. import org.chililog.server.data.RepositoryParserConfigBO;
  25. import org.chililog.server.data.RepositoryEntryBO.Severity;
  26. import com.mongodb.DBObject;
  27. /**
  28. * <p>
  29. * Default parser that does not extract any fields. Just create a {@link RepositoryEntryBO} with keywords.
  30. * </p>
  31. *
  32. * @author vibul
  33. *
  34. */
  35. public class DefaultEntryParser extends EntryParser {
  36. private static Log4JLogger _logger = Log4JLogger.getLogger(DefaultEntryParser.class);
  37. /**
  38. * <p>
  39. * Basic constructor
  40. * </p>
  41. *
  42. * @param repoInfo
  43. * Repository meta data
  44. * @param repoParserInfo
  45. * Parser information that we need
  46. * @throws ChiliLogException
  47. */
  48. public DefaultEntryParser(RepositoryConfigBO repoInfo, RepositoryParserConfigBO repoParserInfo)
  49. throws ChiliLogException {
  50. super(repoInfo, repoParserInfo);
  51. return;
  52. }
  53. /**
  54. * Parse a string for fields. All exceptions are caught and logged. If <code>null</code> is returned, this indicates
  55. * that the entry should be skipped.
  56. *
  57. * @param timestamp
  58. * Time when this log entry was created at the source on the host.
  59. * @param source
  60. * Name of the input device or application that created this text entry
  61. * @param host
  62. * IP address of the input device or application that created this text entry
  63. * @param severity
  64. * Classifies the importance of the entry. Can be the severity code (0-7) or text.
  65. * @param preparsedFields
  66. * Pre-parsed fields in JSON format.
  67. * @param message
  68. * The text for this entry to parse
  69. * @return <code>RepositoryEntryBO</code> ready for saving to mongoDB. If the entry cannot be parsed, then null is
  70. * returned
  71. */
  72. @Override
  73. public RepositoryEntryBO parse(String timestamp,
  74. String source,
  75. String host,
  76. String severity,
  77. String preparsedFields,
  78. String message) {
  79. try {
  80. this.setLastParseError(null);
  81. checkParseArguments(timestamp, source, host, severity, message);
  82. Severity sev = Severity.parse(severity);
  83. ArrayList<String> keywords = parseKeywords(source, host, sev, message);
  84. DBObject fields = this.readPreparsedFields(preparsedFields);
  85. RepositoryEntryBO entry = new RepositoryEntryBO(parseTimestamp(timestamp), source, host, sev, keywords,
  86. message, fields);
  87. return entry;
  88. } catch (Exception ex) {
  89. this.setLastParseError(ex);
  90. _logger.error(ex, "Error parsing text entry: " + message);
  91. return null;
  92. }
  93. }
  94. }