/** * Sends to LogMX the current parsed log entry. * * @throws Exception */ private void recordPreviousEntryIfExists() throws Exception { if (entry != null) { entry.setMessage(entryMsgBuffer.toString()); addEntry(entry); } }
/** * Returns the relative timestamp (execution time) of given entry. * * @see com.lightysoft.logmx.mgr.LogFileParser, * getRelativeEntryDate(com.lightysoft.logmx.business.ParsedEntry) */ public Date getRelativeEntryDate(ParsedEntry pEntry) throws Exception { final String executionTimeString = pEntry.getUserDefinedFields().get(ExecutionTimeKey).toString(); return new Date(Integer.parseInt(executionTimeString)); }
/** * Sends to LogMX the current parsed log entry, then creates a new one. * * @throws Exception */ private void prepareNewEntry() throws Exception { recordPreviousEntryIfExists(); entry = createNewEntry(); entryMsgBuffer = new StringBuilder(80); // Creates an empty Map with only one element allocated: entry.setUserDefinedFields(new HashMap<String, Object>(1)); }
/** * Process the new line of text read from file. * * @see com.lightysoft.logmx.mgr.LogFileParser#parseLine(java.lang.String) */ protected void parseLine(String line) throws Exception { // If end of file, records last entry if necessary, and exits: if (line == null) { recordPreviousEntryIfExists(); return; } Matcher matcher = TraceBeginPattern.matcher(line); if (matcher.matches()) { // Records previous found entry if exists, then create a new one: prepareNewEntry(); // We are at the beginning of a trace. /* '|' is the field separator: */ String[] fields = line.split("\\|"); /* * field #0: technical identifier (PID) -> in entry 'Thread' * * field #1: name of the emitter -> last part in entry * 'Emitter' (useful for automatic hierarchy sorting in the left * panel of the GUI) * * field #2: emitter categorization -> first part in entry * 'Emitter' * * field #3: Execution timestamp -> in entry 'Timestamp' * (called 'Date') * * field #4: Wallclock time -> in entry * 'Wallclock Time' * * field #5: emitter location -> in entry * 'Emitter Location' * * field #6: message categorization -> in entry * 'Message Categorization' * * field #7: priority -> in entry 'Level' * * field #8: message -> in entry Message * Next fields (if ever '|' is in message) are added to message. */ entry.setThread(fields[0].trim()); entry.setEmitter(fields[2].trim() + "." + fields[1].trim()); entry.setDate(fields[3].trim()); entry.setLevel(fields[7].trim()); // From field #8 to all that may remain: String remainingFields = ""; Integer remainingFieldsCount = fields.length - 8; // Puts back the '|': for (Integer i = 0; i < remainingFieldsCount; i++) { remainingFields += fields[i + 8].trim(); if (i != remainingFieldsCount - 1) remainingFields += "|"; } /* * Inserts spaces to allow line-breaking, and end-of-line to * separate additional fields from actual message: * */ entryMsgBuffer.append(remainingFields); // Relative timestamp is also the execution time here: entry.getUserDefinedFields().put(ExecutionTimeKey, fields[4].trim()); entry.getUserDefinedFields().put(EmitterLocationKey, fields[5].trim()); entry.getUserDefinedFields().put(CategoryKey, fields[6].trim()); } else if (entry != null) { // Appending this line to previous entry's text: entryMsgBuffer.append('\n').append(line); } }
/** * Returns the Date object for the given entry * * @see com.lightysoft.logmx.mgr.LogFileParser, * getAbsoluteEntryDate(com.lightysoft.logmx.business.ParsedEntry) */ public Date getAbsoluteEntryDate(ParsedEntry pEntry) throws Exception { return DatePattern.parse(pEntry.getDate()); }