@Override public String format(String mBean, Map<String, String> attributes, long timestamp) { // not using the timestamp, using the SPLUNK index time instead // append the common prefix StringBuffer output = new StringBuffer(); prependDate(timestamp, output); output.append(outputPrefix); // append the mbean name output.append(buildPair("mbean", mBean)); // add mbean attributes Set<String> keys = attributes.keySet(); for (String key : keys) { String value = attributes.get(key); value = FormatterUtils.stripNewlines(value); value = stripPatterns(value); output.append(buildPair(key, value)); } String result = output.toString(); return result.substring(0, result.length() - pairdelim.length()); // just // trim // trailing // pairdelim // character(s) }
// step3: add log item one by one public void addLog( String type, String partName, String parentPart, String threadId, String logPriority, String errorCode, String message, String stackTrace, String dynamicData) { if (csvWriter == null) { return; } String eventDate = FormatterUtils.format_Date(new Date(), "yyyy-MM-dd HH:mm:ss.S"); JobLogItem item = new JobLogItem( eventDate, type, partName, parentPart, threadId, logPriority, errorCode, message, stackTrace, dynamicData); try { if (genDynamicPart) { csvWriter.write(item.eventDate); // eventDate--------------->??? csvWriter.write(commonInfo.pid); // pid csvWriter.write(commonInfo.root_pid); // root_pid csvWriter.write(commonInfo.father_pid); // father_pid } csvWriter.write(item.type); // type---------------->??? csvWriter.write(item.partName); // partName csvWriter.write(item.parentPart); // parentPart if (genDynamicPart) { csvWriter.write(commonInfo.project); // project } csvWriter.write(commonInfo.jobName); // jobName csvWriter.write(commonInfo.jobContext); // jobContext csvWriter.write(commonInfo.jobVersion); // jobVersion csvWriter.write(null); // threadId csvWriter.write(item.logPriority); // logPriority csvWriter.write(item.errorCode); // errorCode csvWriter.write(item.message); // message csvWriter.write(item.stackTrace); // stackTrace csvWriter.write(item.dynamicData); // dynamicData--->it is the 17th field. @see:feature:11296 csvWriter.endRecord(); csvWriter.flush(); // for test the order // System.out.print(item.partName + ",");// partName // System.out.print(item.parentPart + ",");// parentPart // System.out.print(commonInfo.project + ",");// project // System.out.print(commonInfo.jobName + ",");// jobName // System.out.println(); } catch (Exception e) { e.printStackTrace(); } }